Add Royal Flush to the hand_rank
This commit is contained in:
parent
6b262097c3
commit
a30079df3b
@ -50,30 +50,35 @@ class Player:
|
|||||||
rank_counts = {r: ranks.count(r) for r in ranks}
|
rank_counts = {r: ranks.count(r) for r in ranks}
|
||||||
is_flush = len(set(suits)) == 1
|
is_flush = len(set(suits)) == 1
|
||||||
is_straight = all(ranks[i] - 1 == ranks[i+1] for i in range(len(ranks)-1))
|
is_straight = all(ranks[i] - 1 == ranks[i+1] for i in range(len(ranks)-1))
|
||||||
counts = sorted(rank_counts.values(), reverse=True)
|
|
||||||
|
|
||||||
if ranks == [14, 5, 4, 3, 2]: # Ace-low straight
|
# Handle Ace-low straight
|
||||||
|
if ranks == [14, 5, 4, 3, 2]:
|
||||||
is_straight = True
|
is_straight = True
|
||||||
ranks = [5, 4, 3, 2, 1]
|
ranks = [5, 4, 3, 2, 1]
|
||||||
|
|
||||||
|
if is_flush and ranks == [14, 13, 12, 11, 10]:
|
||||||
|
return (9, ranks) # Royal Flush
|
||||||
|
|
||||||
|
counts = sorted(rank_counts.values(), reverse=True)
|
||||||
|
|
||||||
if is_straight and is_flush:
|
if is_straight and is_flush:
|
||||||
return (8, ranks)
|
return (8, ranks) # Straight Flush
|
||||||
elif counts[0] == 4:
|
elif counts[0] == 4:
|
||||||
return (7, ranks)
|
return (7, ranks) # Four of a Kind
|
||||||
elif counts[0] == 3 and counts[1] == 2:
|
elif counts[0] == 3 and counts[1] == 2:
|
||||||
return (6, ranks)
|
return (6, ranks) # Full House
|
||||||
elif is_flush:
|
elif is_flush:
|
||||||
return (5, ranks)
|
return (5, ranks) # Flush
|
||||||
elif is_straight:
|
elif is_straight:
|
||||||
return (4, ranks)
|
return (4, ranks) # Straight
|
||||||
elif counts[0] == 3:
|
elif counts[0] == 3:
|
||||||
return (3, ranks)
|
return (3, ranks) # Three of a Kind
|
||||||
elif counts[0] == 2 and counts[1] == 2:
|
elif counts[0] == 2 and counts[1] == 2:
|
||||||
return (2, ranks)
|
return (2, ranks) # Two Pair
|
||||||
elif counts[0] == 2:
|
elif counts[0] == 2:
|
||||||
return (1, ranks)
|
return (1, ranks) # One Pair
|
||||||
else:
|
else:
|
||||||
return (0, ranks)
|
return (0, ranks) # High Card
|
||||||
|
|
||||||
class Game:
|
class Game:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user