API
TexasHoldem — Module
TexasHoldemA no-limit Texas Holdem simulator.
Terminology
gamea single "game", where players are dealt hands, winner(s) are declared once.rounda point or process in the game (from RoundState)roundthe process of each player deciding which actions to take, until no further actions are taking.
Game-level functions
TexasHoldem.move_buttons! — Function
move_buttons!(table::Table)Move the dealer, small blind, big blind, and first-to-act buttons to the next set of players.
This is an internal method.
sourceTexasHoldem.play! — Function
play!(game::Game[, ::Val{true|false}])Play a game. Users can take a game at an instance and continue that game, by calling play! with Val(false).
TexasHoldem.tournament! — Function
Chips
TexasHoldem.Chips — Type
Chips(n, frac)A stack of chips struct. This type is backed by Ints and performs exact arithmetic operations by using Rational numbers to track remainders (fractions of a chip). frac is always internally stored as less than 1.
Players can only bet/call with whole chips (n), and are not allowed to bet/call with a fraction of a chip.
We track the fractions of chips so that we can assert exact money conservation on the table until a player busts, at which point, that money is lost.
sourcePlayer type and methods
TexasHoldem.AbstractStrategy — Type
TexasHoldem.Human — Type
HumanA human (terminal input) strategy. Use this strategy if you want to play "live" games, and not for simulating games.
sourceTexasHoldem.Bot5050 — Type
Bot5050Bot5050 is a stochastic strategy that chooses all of its actions based on a coin flip.
This bot is used for quick-start game configurations for users.
sourceTexasHoldem.Player — Type
PlayerContains the poker player information:
- strategy
- cards
- bank roll
- pot investment
TODO: some of these fields should be removed, since they're only needed for flow control logic.
sourceTexasHoldem.bank_roll — Function
bank_roll(::Player)The player's instantaneous bank roll.
We access the Int in Chips as the fractional chips are only handled by the TransactionManager.
TexasHoldem.bank_roll_chips — Function
bank_roll_chips(::Player)The player's instantaneous bank roll in Chips (includes fractional chips).
sourceTexasHoldem.round_bank_roll — Function
round_bank_roll(::Player)The player's bank roll at the beginning of the round
We access the Int in Chips as the fractional chips are only handled by the TransactionManager.
Player actions
The call, raise, and all-in functions follow the convetion:
call_amount = total_bet - round_contributionpot_investment = sum(round_contribution, rounds)potthe sum of all round contributionsinitial_round_raise_amountminimum raise amount for all betting cycles in the roundminimum_raise_amountthe minimum raise amount.Call(game)will match the amount of the last bet made in the current betting round. By calling, you stay in the hand.RaiseTo(game, 5)raise the current total bet to 5.AllIn(game)raise all-in (all of your remaining chips). Note thatAllIn(game).amtwill contain the raise above the current total bet.bank_roll(game)
TexasHoldem.Action — Type
ActionAn action type, to be returned by get_action during each players turn to act. This is an internal type, but documented for user understanding.
Users are expected to return an action from get_action by calling one of Action's convenience methods:
TexasHoldem.ActionType — Module
ActionTypeAn action enum type, to be used with Action.
Users are expected to return an action from get_action by calling one of Action's convenience methods:
NoOptionsWaitingFoldCheckCallRaiseAllIn
TexasHoldem.Check — Function
TexasHoldem.Fold — Function
TexasHoldem.Call — Function
Call(game::Game)The call action, should be returned from get_action. when a player wants to call amount amt.
Use call_amount to query how much is needed to call.
TexasHoldem.call_amount — Function
TexasHoldem.RaiseTo — Function
RaiseTo(game::Game, total_bet::Int)The raise-to action, should be returned from get_action. when a player wants to raise the current total bet amount to total_bet.
Use valid_total_bet_range to query the valid range that they are allowed to raise.
When a player returns RaiseTo(game, 5), this means that they want to raise the current total bet to 5.
TexasHoldem.AllIn — Function
AllIn(game::Game)The all-in action, should be returned from get_action. when a player wants to raise all-in.
action = AllIn(game) will contain the amount to go all-in.
Users may call this via AllIn(game).
See valid_total_bet_range for querying the valid range that they are allowed to raise.
TexasHoldem.valid_total_bet_range — Function
valid_total_bet_range(table::Table, player::Player)A UnitRange{Int} of valid raises. Note that sometimes the range's starting and ending values are the same when, for example, all-in is the only available option.
TexasHoldem.get_action — Function
get_action(game::Game, player::Player, options::Options)Returns a valid action (see Action), given the allowable options. TexasHoldem calls get_action for each player on the table during each round. This function is entirely where the strategy logic resides.
Users may overload this method to develop their own poker bots. The options type is of type Options and has one of the following names
CheckRaiseFoldCallRaiseFoldCallAllInFoldCallFold
Additional helpers:
TexasHoldem.total_bet — Function
TexasHoldem.is_valid_action — Function
is_valid_action(game, a::Action, options::Options)Returns a Bool indicating that the given action is valid given the options
sourceTexasHoldem.action_validation_code — Function
action_validation_code(game::Game, action::Action, options::Options)Returns an ActionValidationCode for the given action and options.
sourceTexasHoldem.round_contribution — Function
Player options
TexasHoldem.Options — Type
OptionsAn options enum type, to be returned by get_options. Users can use this to determine which action to give back to play.
Helper functions to return allowable options include:
NoOptionsCheckRaiseFoldCallRaiseFoldCallAllInFoldCallFold
TexasHoldem.get_options — Function
Action and Options symbols
An Action has an action_type and an amount amt. The action_type is an enum type, with the following values:
FoldCheckCallRaiseAllIn
The allowable enum Options are:
NoOptionsCheckRaiseFoldCallRaiseFoldCallAllInFoldCallFold
get_options(game::Game) will always yield a valid Options object, TexasHoldem cannot guarantee that a user will yield a valid action. Use is_valid_action(game::Game, action::Action, options::Options)::Bool to determine if a given action is valid or not.
Action validation
Simply use @assert action_validation_code(game, action, options) == ActionValidationCode.ValidAction to validation a given action under the current options options. See ActionValidationCode for the action validation codes.
TexasHoldem.ActionValidationCode — Module
ActionValidationCodeAn action validation code enum type.
NoOptionsWaitingFoldCheckCallRaiseAllIn
States
TexasHoldem.GameState — Module
TexasHoldem.RoundState — Module
Training
There are additional functionalities added for training purposes
TexasHoldem.recreate_game — Function
recreate_game(game, player)Creates an exact (deep)copy of the input game, and then re-samples the unobserved cards (i.e., the opponent cards and unobserved table cards).
This is useful for repeatedly sampling a specific scenario so that we can compute the expected value of a particular action.
TODO: we could make a mutating, in-place version of this to reduce allocations.
source