poker_ai.poker package¶
Subpackages¶
Submodules¶
poker_ai.poker.actions module¶
-
class
poker_ai.poker.actions.
Call
¶ Bases:
poker_ai.poker.actions.Action
-
class
poker_ai.poker.actions.
Fold
¶ Bases:
poker_ai.poker.actions.Action
-
class
poker_ai.poker.actions.
Raise
¶ Bases:
poker_ai.poker.actions.Action
poker_ai.poker.card module¶
-
class
poker_ai.poker.card.
Card
(rank: Union[str, int], suit: str)¶ Bases:
object
Card to represent a poker card.
-
__repr__
()¶ Pretty printing the object.
-
_rank_to_char
(rank: int) → str¶ Convert the int rank to char used by the EvaluationCard object.
-
_rank_to_str
(rank: int) → str¶ Convert the integer rank to the string rank.
-
_str_to_rank
(string: str) → int¶ Convert the string rank to the integer rank.
-
_suit_to_icon
(suit: str) → str¶ Icons for pretty printing.
-
property
eval_card
¶ Return an EvaluationCard for use in the Evaluator.
-
static
from_dict
(x: Dict[str, Union[int, str]])¶ From dict turn into class.
-
property
rank
¶ Get the rank as a string.
-
property
rank_int
¶ Get the rank as an int
-
property
suit
¶ Get the suit.
-
to_dict
() → Dict[str, Union[int, str]]¶ Turn into dict.
-
-
poker_ai.poker.card.
get_all_ranks
() → List[str]¶ Get the list of ranks the card could be.
-
poker_ai.poker.card.
get_all_suits
() → Set[str]¶ Get set of suits that the card can take on.
poker_ai.poker.dealer module¶
-
class
poker_ai.poker.dealer.
Dealer
(**deck_kwargs)¶ Bases:
object
The dealer is in charge of handling the cards on a poker table.
-
deal_card
() → Card¶ Return a completely random card.
-
deal_community_cards
(table: PokerTable, n_cards: int)¶ Deal public cards.
-
deal_flop
(table: PokerTable)¶ Deal the flop public cards to the table.
-
deal_private_cards
(players: List[Player])¶ Deal private card to players.
- Parameters
players (list of Player) – The players to deal the private cards to.
-
deal_river
(table: PokerTable)¶ Deal the river public cards to the table.
-
deal_turn
(table: PokerTable)¶ Deal the turn public cards to the table.
-
poker_ai.poker.deck module¶
-
class
poker_ai.poker.deck.
Deck
(include_suits: List[str] = ['diamonds', 'hearts', 'clubs', 'spades'], include_ranks: List[int] = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14])¶ Bases:
object
Class to manage the deck.
-
__len__
() → int¶ Return overall length of the deck.
-
pick
(random: bool = True) → poker_ai.poker.card.Card¶ Return a card from the deck.
- Parameters
random (bool) – If this is true, return a completely random card, else return the next card in the deck.
- Returns
card – The card that was picked.
- Return type
-
remove
(card)¶ Remove a specific card from the deck
-
reset
()¶ Reset the deck and shuffle it, ready for use.
-
poker_ai.poker.engine module¶
-
class
poker_ai.poker.engine.
PokerEngine
(table: PokerTable, small_blind: int, big_blind: int)¶ Bases:
object
Instance to represent the lifetime of a full poker hand.
A hand of poker is played at a table by playing for betting rounds: pre-flop, flop, turn and river. Small blind and big blind can be set per hand, but should generally not change during a session on the table.
-
_all_active_players_take_action
(first_round: bool)¶ Force all players to make a move.
-
_all_dealing_and_betting_rounds
()¶ Run through dealing of all cards and all rounds of betting.
-
_assign_blinds
()¶ Assign the blinds to the players.
-
_assign_order_to_players
()¶ Assign order of play to each player (to aid sorting in payouts).
-
_bet_until_everyone_has_bet_evenly
()¶ Iteratively bet until all have put the same num chips in the pot.
-
_betting_round
(first_round: bool = False)¶ Computes the round(s) of betting.
Until the current betting round is complete, all active players take actions in the order they were placed at the table. A betting round lasts until all players either call the highest placed bet or fold.
-
_compute_payouts
(ranked_player_groups: List[Player])¶ Find the highest ranked players for each sidepot and get winnings
-
_get_players_in_pot
(player_group, pot)¶ Return the players in the pot, ordered by hand played.
-
_move_blinds
()¶ Rotate the table’s player list.
This is so that the next player in line gets the small blind and the right to act first in the next hand.
-
_payout_players
(payouts: Dict[Player, int])¶ Remove money from the pot and pay the winning players the chips.
-
_players_in_order_of_betting
(first_round: bool) → List[Player]¶ Players bet in different orders depending on the round it is.
-
_post_betting_analysis
()¶ Log objects and run checks at the end of each round of betting.
-
_process_side_pot
(player_group, pot)¶ Check if this list of players contributed to this side pot.
-
_rank_players_by_best_hand
() → List[List[Player]]¶ Rank all players hands and return the players in order of rank.
-
_round_cleanup
()¶ Any code that must be called at the end of a round.
-
property
all_bets
¶ Returns all bets made by the players.
-
compute_winners
()¶ Compute winners and payout the chips to respective players.
-
property
more_betting_needed
¶ Returns if more bets are required to terminate betting.
If all active players have settled, i.e everyone has called the highest bet or folded, the current betting round is complete, else, more betting is required from the active players that are not all in.
-
property
n_active_players
¶ Returns the number of active players.
-
property
n_all_in_players
¶ Return the amount of players that are active and that are all in.
-
property
n_players_with_moves
¶ Returns the amount of players that can freely make a move.
-
play_one_round
()¶
-
round_setup
()¶ Code that must be done to setup the round before the game starts.
-
poker_ai.poker.player module¶
-
class
poker_ai.poker.player.
Player
(name: str, initial_chips: int, pot: Pot)¶ Bases:
object
Abstract base class for all poker-playing agents.
All agents should inherit from this class and implement the take_action method.
A poker player has a name, holds chips to bet with, and has private cards to play with. The n_chips of contributions to the pot for a given hand of poker are stored cumulative, as the total pot to cash out is just the sum of all players’ contributions.
-
_try_to_make_full_bet
(n_chips: int)¶ Ensures no bet is greater than the n_chips of chips left.
-
add_chips
(chips: int)¶ Add chips.
-
add_private_card
(card: Card)¶ Add a private card to this player.
-
add_to_pot
(n_chips: int)¶ Add to the n_chips put into the pot by this player.
-
call
(players: List[poker_ai.poker.player.Player])¶ Call the highest bet among all active players.
-
fold
()¶ Deactivate player for this hand by folding cards.
-
property
is_active
¶ Getter for if the player is playing or not.
-
property
is_all_in
¶ Return if the player is all in or not.
-
property
n_bet_chips
¶ Returns the n_chips this player has bet so far.
-
raise_to
(n_chips: int)¶ Raise your bet to a certain n_chips.
-
take_action
(game_state: poker_ai.poker.state.PokerGameState) → poker_ai.poker.state.PokerGameState¶ All poker strategy is implemented here.
Smart agents have to implement this method to compete. To take an action, agents receive the current game state and have to emit the next state.
-
poker_ai.poker.pot module¶
-
class
poker_ai.poker.pot.
Pot
¶ Bases:
object
-
__getitem__
(player: poker_ai.poker.player.Player)¶ Get a players contribution to the pot.
-
__repr__
()¶ Nicer way to print a Pot object.
-
add_chips
(player: poker_ai.poker.player.Player, n_chips: int)¶ Add chips to the pot, from a player for a given round.
-
reset
()¶ Reset the pot.
-
property
side_pots
¶ Compute the side pots.
-
property
total
¶ Return the total in the pot from all players.
-
property
uid
¶ Get a unique identifier for this pot.
-
poker_ai.poker.random_player module¶
-
class
poker_ai.poker.random_player.
RandomPlayer
(name: str, initial_chips: int, pot: poker_ai.poker.pot.Pot, fold_probability: float = 0.1, raise_probability: float = 0.1, call_probability: float = 0.8)¶ Bases:
poker_ai.poker.player.Player
Complete a dummy agent largely for development purposes. Extends the poker_ai.game.player.Player class so inherits all of that functionality. The agent will make a move based on the probabilities set in the constructor, so you can weight the chances of it taking various actions for a given turn.
-
_random_move
(players: List[poker_ai.poker.player.Player])¶ Make a random move.
-
take_action
(game_state: poker_ai.poker.state.PokerGameState) → poker_ai.poker.state.PokerGameState¶ All poker strategy is implemented here.
Smart agents have to implement this method to compete. To take an action, agents receive the current game state and have to emit the next state.
-
poker_ai.poker.state module¶
-
class
poker_ai.poker.state.
PokerGameState
(previous_state, table, player, action, is_terminal)¶ Bases:
object
Poker game state is encoded as an immutable data structure.
At each point in time a poker game is described by the information on the table and the player whose turn it is taking an action, plus all previous states.
-
__repr__
()¶ Make a nice printable node.
-
property
current_player
¶ Get the current player.
-
property
is_chance_node
¶
-
property
is_terminal
¶
-
classmethod
new_hand
(table)¶
-
property
table
¶
-
property
utility
¶
-
poker_ai.poker.table module¶
-
class
poker_ai.poker.table.
PokerTable
(players: List[Player], pot: Pot, **deck_kwargs)¶ Bases:
object
On a poker table a minimum of two players and one dealer are seated.
You also find the community cards on it and can see the current pot size. Each player is responisble for handling his own cards privately.
-
__repr__
()¶ Get a nice print out in the debugger for the table.
-
add_community_card
(card: Card)¶ Add a public card to the table for all players to use.
-
property
n_players
¶ How many players are on the table?
-
set_players
(players: List[Player])¶ Set the players.
-