@@ -118,10 +118,8 @@ def poker_has_straight(hand):
118
118
hand_ranks = [ranks [rank ] for (rank , _ ) in hand ]
119
119
min_rank , max_rank = min (hand_ranks ), max (hand_ranks )
120
120
if max_rank == 14 : # Special cases for straights with an ace
121
- if min_rank == 10 :
122
- return True # AKQJT, Broadway straight
123
- return sorted (hand ) == [2 , 3 , 4 , 5 , 14 ] # A2345, bicycle straight
124
- else :
121
+ return min_rank == 10 or sorted (hand ) == [2 , 3 , 4 , 5 , 14 ]
122
+ else : # Hand has no aces, so it must be five consecutive ranks
125
123
return max_rank - min_rank == 4
126
124
127
125
@@ -161,44 +159,10 @@ def evaluate_all_poker_hands():
161
159
if f (hand ):
162
160
counters [i ] += 1
163
161
break # No point looking for more for this hand
164
- return [(f .__name__ , counters [i ]) for (i , f ) in enumerate (funcs )]
162
+ result = [(f .__name__ , counters [i ]) for (i , f ) in enumerate (funcs )]
163
+ assert sum (c for (_ , c ) in result ) == 2598960
164
+ return result
165
165
166
166
167
- # Compute the resulting score of a made contract in contract bridge.
168
-
169
- def bridge_score (suit , level , vul , dbl , made ):
170
- mul = {'X' : 2 , 'XX' : 4 }.get (dbl , 1 )
171
- score , bonus = 0 , 0
172
-
173
- # Add up the values of individual tricks.
174
- for trick in range (1 , made + 1 ):
175
- # Raw points for this trick.
176
- if suit == 'clubs' or suit == 'diamonds' :
177
- pts = 20
178
- elif suit == 'hearts' or suit == 'spades' :
179
- pts = 30
180
- else :
181
- pts = 40 if trick == 1 else 30
182
- # Score from the raw points.
183
- if trick <= level : # Part of contract
184
- score += mul * pts
185
- elif mul == 1 : # Undoubled overtrick
186
- bonus += mul * pts
187
- elif mul == 2 : # Doubled overtrick
188
- bonus += 200 if vul else 100
189
- else : # Redoubled overtrick
190
- bonus += 400 if vul else 200
191
- if score >= 100 : # Game bonus
192
- bonus += 500 if vul else 300
193
- else : # Partscore bonus
194
- bonus += 50
195
- if level == 6 : # Small slam bonus
196
- bonus += 750 if vul else 500
197
- if level == 7 : # Grand slam bonus
198
- bonus += 1500 if vul else 1000
199
- score += bonus
200
- if mul == 2 : # Insult bonus for making a (re)doubled contract
201
- score += 50
202
- elif mul == 4 :
203
- score += 100
204
- return score
167
+ if __name__ == "__main__" :
168
+ print (evaluate_all_poker_hands ())
0 commit comments