Some useful things you can do.
Complete post can be done in a notbook.
Add more description here ...
# https://poker.readthedocs.io/en/latest/api/handhistory.html
from poker import Suit
[Suit('♣'), Suit('♦'), Suit('♥'), Suit('♠')]
from poker.hand import Hand, Combo, Range, Card
Hand('AKs') < Hand('AKo')
range = Range('22+ 54s 76s 98s AQo+')
Combo('5♥4♥') in range.combos
Range('77+,ATs+,KJs+,JTs,T9s,98s,AQo+').percent
%%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 | | QQ | | | | | | | | | | |
| | | JJ | JTs | | | | | | | | |
| | | | TT | T9s | | | | | | | |
| | | | | 99 | 98s | | | | | | |
| | | | | | 88 | | | | | | |
| | | | | | | 77 | | | | | |
| | | | | | | | | | | | |
| | | | | | | | | | | | |
| | | | | | | | | | | | |
| | | | | | | | | | | | |
| | | | | | | | | | | | |
# https://github.com/ihendley/treys
from treys import Card
Card.print_pretty_card(card)
board = [
Card.new('Ah'),
Card.new('Kd'),
Card.new('Jc')
]
hand = [
Card.new('Qs'),
Card.new('Th')
]
Card.print_pretty_cards(board + hand)
from treys import Evaluator
evaluator = Evaluator()
print(evaluator.evaluate(board, hand))
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