Some useful things you can do.
Complete post can be done in a notbook. All kinds of text can go in here. You can rant and rand for as long as you want.
# https://poker.readthedocs.io/en/latest/api/handhistory.html
from poker import Suit
list(Suit)
[Suit('♣'), Suit('♦'), Suit('♥'), Suit('♠')]
from poker.hand import Hand, Combo, Range, Card
Hand.make_random()
Hand('J6s')
Or you can note things that are worth noting.
Hand('AA') > Hand('KK')
True
Hand('KK') > Hand('AA')
False
hand = Hand('AKs').first
hand.val
'A'
Hand('AKs') < Hand('AKo')
False
range = Range('22+ 54s 76s 98s AQo+')
Combo('5♥4♥') in range.combos
True
len(Range('AKs').combos)
4
len(Range('AKo').combos)
12
len(Range('TT').combos)
6
Range('77+,ATs+,KJs+,JTs,T9s,98s,AQo+').percent
8.14
%%html
<style>
td {
width: 30px;
height: 30px;
text-align: center;
vertical-align: middle;
}
td.pair {
background: #aaff9f;
border: 1px solid black;
}
td.offsuit {
background: #bbced3;
border: 1px solid black;
}
td.suited {
background: #e37f7d;
border: 1px solid black;
}
</style>
from IPython.core.display import HTML
HTML(Range('77+,ATs+,KJs+,JTs,T9s,98s,AQo+').to_html())
AA | AKs | AQs | AJs | ATs | ||||||||
AKo | KK | KQs | KJs | |||||||||
AQo | ||||||||||||
JJ | JTs | |||||||||||
TT | T9s | |||||||||||
99 | 98s | |||||||||||
88 | ||||||||||||
77 | ||||||||||||
# https://github.com/ihendley/treys
from treys import Card
card = Card.new('Qh')
card
67119647
Card.print_pretty_card(card)
[Q♥]
board = [
Card.new('Ah'),
Card.new('Kd'),
Card.new('Jc')
]
hand = [
Card.new('Qs'),
Card.new('Th')
]
Card.print_pretty_cards(board + hand)
[A♥],[K♦],[J♣],[Q♠],[T♥]
from treys import Evaluator
evaluator = Evaluator()
print(evaluator.evaluate(board, hand))
1600
from treys import Deck
deck = Deck()
board = deck.draw(5)
player1_hand = deck.draw(2)
player2_hand = deck.draw(2)
player3_hand = deck.draw(2)
Card.print_pretty_cards(board)
Card.print_pretty_cards(player1_hand)
Card.print_pretty_cards(player2_hand)
Card.print_pretty_cards(player3_hand)
[K♥],[K♣],[8♥],[4♣],[7♠]
[9♦],[9♥]
[K♠],[A♠]
[7♦],[6♦]
def evaluate_hand(name, hand, board):
score = evaluator.evaluate(board, hand)
cls = evaluator.get_rank_class(score)
cls_str = evaluator.class_to_string(cls)
print(f"Player {name} hand rank = {score} ({cls_str})")
hands = [player1_hand, player2_hand, player3_hand]
for i, hand in enumerate(hands):
evaluate_hand(i+1, hand, board)
evaluator.hand_summary(board, hands)
Player 1 hand rank = 2637 (Two Pair)
Player 2 hand rank = 1680 (Three of a Kind)
Player 3 hand rank = 2660 (Two Pair)
========== FLOP ==========
Player 1 hand = Two Pair, percentage rank among all hands = 0.6466094880729027
Player 2 hand = Three of a Kind, percentage rank among all hands = 0.774859287054409
Player 3 hand = Pair, percentage rank among all hands = 0.5
Player 2 hand is currently winning.
========== TURN ==========
Player 1 hand = Two Pair, percentage rank among all hands = 0.6466094880729027
Player 2 hand = Three of a Kind, percentage rank among all hands = 0.774859287054409
Player 3 hand = Pair, percentage rank among all hands = 0.5
Player 2 hand is currently winning.
========== RIVER ==========
Player 1 hand = Two Pair, percentage rank among all hands = 0.6466094880729027
Player 2 hand = Three of a Kind, percentage rank among all hands = 0.774859287054409
Player 3 hand = Two Pair, percentage rank among all hands = 0.6435272045028142
========== HAND OVER ==========
Player 2 is the winner with a Three of a Kind
Poker with Python.
https://www.datacamp.com/tutorial/statistics-python-tutorial-probability-1#ev
https://www.datacamp.com/tutorial/python-probability-tutorial