Skip to content

Commit

Permalink
The CCCC implementation had the very final step missing (#33)
Browse files Browse the repository at this point in the history
* The CCCC implementation had the very final step missing

* fix evaluate test for cccc

---------

Co-authored-by: Dominic Price <dominicprice@outlook.com>
  • Loading branch information
EmanuelU and dominicprice authored Nov 17, 2023
1 parent 3d00734 commit b84bbb8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ CMakeSettings.json
*.sln
.env

# Intellij local config files
.idea/

# Virtual environment
venv/
.python-version
Expand Down
5 changes: 4 additions & 1 deletion src/endplay/evaluate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,10 @@ def cccc(hand: Union[Hand, SuitHolding]) -> float:
described on http://www.rpbridge.net/8j19.htm
"""
if isinstance(hand, Hand):
return sum(cccc(hand[suit]) for suit in Denom.suits())
part = sum(cccc(hand[suit]) for suit in Denom.suits()) - 1
if shape(hand) == [4, 3, 3, 3]:
return part + 0.5
return part
l = len(hand)
score = 0.0
# 1-5: Count point values A=4,K=3,Q=2,J=1,T=0.5
Expand Down
11 changes: 6 additions & 5 deletions tests/test_evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,17 @@ def test_losers(self):

def test_cccc(self):
# These test cases can be generated by choosing the Random Hand
# option on http://rpbridge.net/cgi-bin/xhe1.pl and ignoring
# the Kaplan-Rubens adjustment
# option on http://rpbridge.net/cgi-bin/xhe1.pl
suit = SuitHolding("AQT432")
self.assertEqual(cccc(suit), 8.45)
hand1 = Hand("A2.6.J97532.AQ85")
self.assertEqual(cccc(hand1), 13.8)
self.assertEqual(cccc(hand1), 12.8)
hand2 = Hand("A6.K954.A93.A984")
self.assertEqual(cccc(hand2), 17)
self.assertEqual(cccc(hand2), 16)
hand3 = Hand("73.t84.qt753.kj3")
self.assertEqual(cccc(hand3), 6.6)
self.assertEqual(cccc(hand3), 5.6)
hand4 = Hand("KQ54.T65.Q52.A43")
self.assertEqual(cccc(hand4), 10.2)

def test_rule_of_n(self):
deal = self.deal
Expand Down

0 comments on commit b84bbb8

Please sign in to comment.