A texasholdem python package
Project description
texasholdem
A python package for Texas Hold 'Em Poker.
Quickstart Guide
Starting a game is as simple as the following:
from texasholdem import TexasHoldEm
game = TexasHoldEm(buyin=500,
big_blind=5,
small_blind=2,
max_players=9)
game.start_hand()
while game.is_hand_running():
game.take_action(...)
Game Information
Get game information and take actions through intuitive attributes:
from texasholdem import TexasHoldEm, HandPhase, ActionType
game = TexasHoldEm(buyin=500,
big_blind=5,
small_blind=2,
max_players=9)
game.start_hand()
assert game.hand_phase == HandPhase.PREFLOP
assert HandPhase.PREFLOP.next_phase() == HandPhase.FLOP
assert game.chips_to_call(game.current_player) == game.big_blind
game.take_action(ActionType.CALL)
game.take_action(ActionType.RAISE, value=10)
assert game.chips_to_call(game.current_player) == 10 - game.big_blind
Card Module
The card module represents cards as 32-bit integers for simple and fast hand
evaluations. For more information about the representation, see the Card
module.
from texasholdem.card import Card
card = Card("Kd") # King of Diamonds
assert isinstance(card, int) # True
assert card.rank == 11 # 2nd highest rank (0-12)
assert card.pretty_string == "[ K ♦ ]"
The game.get_hand(player_id=...)
method of the TexasHoldEm
class
will return a list of type list[Card]
.
Evaluator Module
The evaluator module returns the rank of the best 5-card hand from a list of 5 to 7 cards.
The rank is a number from 1 (strongest) to 7462 (weakest). This determines the winner in the TexasHoldEm
module:
from texasholdem.card import Card
from texasholdem.evaluator import evaluate, rank_to_string
assert evaluate(cards=[Card("Kd"), Card("5d")],
board=[Card("Qd"),
Card("6d"),
Card("5s"),
Card("2d"),
Card("5h")]) == 927
assert rank_to_string(927) == "Flush, King High"
Development
We use python poetry for development make sure you have poetry installed. To install all dependencies run the following from the root project directory:
poetry install
poetry update
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for texasholdem-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 423020fce801adf651e2be47c5a2aaf4eb96881fb1e25005f051b16384fc59b1 |
|
MD5 | f466b5ee2d10cc2b23553b5ff7e0bfad |
|
BLAKE2b-256 | 3234fab2254a764227eb1ae85883ee935ffa29d9888266384dc3827b92bffbee |