In [26]:
from card_games import TexasHoldem, Poker, Deck

In [25]:
p = TexasHoldem(num_players=5)
p.shuffle()
print(f'players: {p.players}')
print(f'table: {p.table}')
print(f'winners: {p.winners}')
print(f'evaluate hand of player 0: {p.evaluate_hand(p.player(0))}')
hand = ['6♣', '2♠', '6♠', '6♥', 'A♥', '8♦']
print(f'evaluate the hand {hand}: {p.evaluate_hand(hand)}')


players: [['5♣', '2♦'], ['J♥', '9♠'], ['9♦', 'K♦'], ['3♦', '3♣'], ['7♥', 'A♣']]
table: ['5♥', 'J♣', 'A♥', '8♦', '8♥']
winners: {4: ((3, 'two pairs'), (14, 14, 8, 8), (11, 7, 5), (3, 1, 3, 2), (1, 3, 3))}
evaluate hand of player 0: ((1, 'highest rank'), (5,), (2,), (1,), (2,))
evaluate the hand ['6♣', '2♠', '6♠', '6♥', 'A♥', '8♦']: ((4, 'three'), (6, 6, 6), (14, 8, 2), (4, 3, 1), (3, 2, 4))

In [36]:
d = Deck()
print(d.suits_weight)
print(d.ranks_weight)
print(p.get_hand_categories().keys())


{'♣': 1, '♦': 2, '♥': 3, '♠': 4}
{'2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, 'T': 10, 'J': 11, 'Q': 12, 'K': 13, 'A': 14}
dict_keys([(1, 'highest rank'), (2, 'pair'), (3, 'two pairs'), (4, 'three'), (5, 'straight'), (6, 'flush'), (7, 'full house'), (8, 'four'), (9, 'straight flush'), (10, 'royal straight flush')])

In [37]:
H = ['6♣', '2♠', '6♠', '6♥', 'A♥', '8♦', '2♥','3♥', '4♦', 'Q♣', 'K♥', '9♥', '5♥']
print(H)


['6♣', '2♠', '6♠', '6♥', 'A♥', '8♦', '2♥', '3♥', '4♦', 'Q♣', 'K♥', '9♥', '5♥']

In [5]:
p._sorted_rank(H)


Out[5]:
['A♥', 'K♥', 'Q♣', '9♥', '8♦', '6♣', '6♠', '6♥', '5♥', '4♦', '3♥', '2♠', '2♥']

In [6]:
p._sorted_suit(H)


Out[6]:
['2♠', '6♠', '6♥', 'A♥', '2♥', '3♥', 'K♥', '9♥', '5♥', '8♦', '4♦', '6♣', 'Q♣']

In [7]:
p.sorted_hand(H)


Out[7]:
['A♥', 'K♥', 'Q♣', '9♥', '8♦', '6♠', '6♥', '6♣', '5♥', '4♦', '3♥', '2♠', '2♥']

In [8]:
p._sorted_suit(p._sorted_rank(H))


Out[8]:
['6♠', '2♠', 'A♥', 'K♥', '9♥', '6♥', '5♥', '3♥', '2♥', '8♦', '4♦', 'Q♣', '6♣']

In [9]:
print(p.sorted_hand(H), '\n')
for (a,b),c in p.get_hand_categories().items():
    print(a,b,c(H), '\n')


['A♥', 'K♥', 'Q♣', '9♥', '8♦', '6♠', '6♥', '6♣', '5♥', '4♦', '3♥', '2♠', '2♥'] 

1 highest rank (['A♥'], ['K♥', 'Q♣', '9♥', '8♦', '6♠', '6♥', '6♣', '5♥', '4♦', '3♥', '2♠', '2♥']) 

2 pair (['6♠', '6♥'], ['A♥', 'K♥', 'Q♣', '9♥', '8♦', '6♣', '5♥', '4♦', '3♥', '2♠', '2♥']) 

3 two pairs (['6♠', '6♥', '2♠', '2♥'], ['A♥', 'K♥', 'Q♣', '9♥', '8♦', '6♣', '5♥', '4♦', '3♥']) 

4 three (['6♠', '6♥', '6♣'], ['A♥', 'K♥', 'Q♣', '9♥', '8♦', '5♥', '4♦', '3♥', '2♠', '2♥']) 

5 straight (['5♥', '4♦', '3♥', '2♠', 'A♥'], ['K♥', 'Q♣', '9♥', '8♦', '6♠', '6♥', '6♣', '2♥']) 

6 flush (['A♥', 'K♥', '9♥', '6♥', '5♥'], ['Q♣', '8♦', '6♠', '6♣', '4♦', '3♥', '2♠', '2♥']) 

7 full house (['6♠', '6♥', '6♣', '2♠', '2♥'], ['A♥', 'K♥', 'Q♣', '9♥', '8♦', '5♥', '4♦', '3♥']) 

8 four ([], ['A♥', 'K♥', 'Q♣', '9♥', '8♦', '6♠', '6♥', '6♣', '5♥', '4♦', '3♥', '2♠', '2♥']) 

9 straight flush ([], ['A♥', 'K♥', 'Q♣', '9♥', '8♦', '6♠', '6♥', '6♣', '5♥', '4♦', '3♥', '2♠', '2♥']) 

10 royal straight flush ([], ['A♥', 'K♥', 'Q♣', '9♥', '8♦', '6♠', '6♥', '6♣', '5♥', '4♦', '3♥', '2♠', '2♥']) 


In [10]:
p.evaluate_hand(H)


Out[10]:
((7, 'full house'),
 (6, 6, 6, 2, 2),
 (14, 13, 12, 9, 8, 5, 4, 3),
 (4, 3, 1, 4, 3),
 (3, 3, 1, 3, 2, 3, 2, 3))

In [11]:
for i in range(10000):
    p = Poker(num_players=8)
    p.shuffle()
    r = p.evaluate_players()
    if len(p.winners.items())>1:
        break
r


Out[11]:
{0: ((1, 'highest rank'), (11,), (10, 8, 5, 3), (4,), (4, 3, 1, 2)),
 1: ((1, 'highest rank'), (14,), (13, 8, 4, 2), (1,), (1, 1, 3, 1)),
 2: ((1, 'highest rank'), (14,), (13, 12, 7, 6), (4,), (3, 3, 3, 1)),
 3: ((1, 'highest rank'), (10,), (9, 8, 5, 4), (3,), (1, 4, 4, 1)),
 4: ((1, 'highest rank'), (11,), (10, 7, 6, 4), (2,), (2, 4, 3, 4)),
 5: ((1, 'highest rank'), (14,), (13, 12, 7, 6), (2,), (4, 2, 2, 4)),
 6: ((1, 'highest rank'), (13,), (12, 6, 5, 3), (2,), (1, 2, 3, 3)),
 7: ((1, 'highest rank'), (11,), (10, 7, 3, 2), (1,), (1, 1, 1, 2))}

In [12]:
p.winners


Out[12]:
{2: ((1, 'highest rank'), (14,), (13, 12, 7, 6), (4,), (3, 3, 3, 1)),
 5: ((1, 'highest rank'), (14,), (13, 12, 7, 6), (2,), (4, 2, 2, 4))}

In [13]:
p.winner


Out[13]:
(5, ((1, 'highest rank'), (14,), (13, 12, 7, 6), (2,), (4, 2, 2, 4)))

In [14]:
p.players


Out[14]:
[['T♠', '8♥', 'J♠', '3♦', '5♣'],
 ['A♣', '4♥', 'K♣', '8♣', '2♣'],
 ['K♥', 'A♠', '7♥', '6♣', 'Q♥'],
 ['4♣', 'T♥', '5♠', '8♠', '9♣'],
 ['6♥', '7♠', '4♠', 'J♦', 'T♦'],
 ['6♠', 'Q♦', '7♦', 'A♦', 'K♠'],
 ['K♦', '5♥', 'Q♣', '3♥', '6♦'],
 ['T♣', '3♣', '2♦', 'J♣', '7♣']]

In [15]:
p.table


Out[15]:
[]

In [ ]: