API
TexasHoldem
— ModuleTexasHoldem
A no-limit Texas Holdem simulator.
Terminology
game
a single "game", where players are dealt hands, winner(s) are declared once.round
a point or process in the game, including:preflop
,:flop
,:turn
,:river
.round
the process of each player deciding which actions to take, until no further actions are taking.
Game-level functions
TexasHoldem.move_buttons!
— Functionmove_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.
TexasHoldem.play!
— Functionplay!(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!
— Functiontournament!(game::Game)
Play until a single player remains!
Chips
TexasHoldem.Chips
— TypeChips(n, frac)
A stack of chips struct. This type is backed by Int
s 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.
Player type and methods
TexasHoldem.AbstractStrategy
— TypeAbstractStrategy
An abstract strategy type, which users can subtype when passing to players.
TexasHoldem.Human
— TypeHuman
A human (terminal input) strategy. Use this strategy if you want to play "live" games, and not for simulating games.
TexasHoldem.Bot5050
— TypeBot5050
Bot5050
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.
TexasHoldem.Player
— TypePlayer
Contains 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.
TexasHoldem.bank_roll
— Functionbank_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
— Functionbank_roll_chips(::Player)
The player's instantaneous bank roll in Chips (includes fractional chips).
TexasHoldem.round_bank_roll
— Functionround_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_contribution
pot_investment = sum(round_contribution, rounds)
pot
the sum of all round contributionsinitial_round_raise_amount
minimum raise amount for all betting cycles in the roundminimum_raise_amount
the 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.Raise(game, 5)
raises 5 above the current total bet.AllIn(game)
raise all-in (all of your remaining chips). Note thatAllIn(game).amt
will contain the raise above the current total bet.bank_roll(game)
TexasHoldem.Action
— TypeAction
An 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:
Options names ((options::Options).name
) are Symbol
s that can be only one of:
:NoOptions
:CheckRaiseFold
:CallRaiseFold
:CallAllInFold
:CallFold
TexasHoldem.Check
— FunctionCheck()
The check action, to be returned from get_action
, when a player wants to check.
TexasHoldem.Fold
— FunctionFold()
The fold action, to be returned from get_action
, when a player wants to fold.
TexasHoldem.Call
— FunctionCall(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
— Functioncall_amount(table::Table, player::Player)
Return the amount to call inside get_action
.
TexasHoldem.Raise
— FunctionRaise(game::Game, amt::Int)
The raise action, should be returned from get_action
. when a player wants to raise to amount amt
.
Use valid_total_bet_range
to query the valid range that they are allowed to raise.
When a player returns Raise(5)
, this means that they want to raise 5 above the current total bet.
TexasHoldem.RaiseTo
— FunctionRaiseTo(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
— FunctionAllIn(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
— Functionvalid_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
— Functionget_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
options.name == :CheckRaiseFold
options.name == :CallRaiseFold
options.name == :CallAllInFold
options.name == :CallFold
Additional helpers:
TexasHoldem.total_bet
— Functiontotal_bet(game::Game)
total_bet(table::Table)
The total bet.
TexasHoldem.is_valid_action
— Functionis_valid_action(game, a::Action, options::Options)
Returns a Bool indicating that the given action is valid given the options
TexasHoldem.validate_action
— Functionvalidate_action(game::Game, action::Action, options::Options)
This method will assert that the given action is valid under the given options.
TexasHoldem.round_contribution
— Functionround_contribution
The contribution for the round
Player options
TexasHoldem.Options
— TypeOptions
An options type, returned by get_options
. Users can use this to determine which action to give back to play
.
Helper functions to return allowable options include:
Actions names ((action::Action).name
) are Symbol
s that can be only one of:
:Fold
:Check
:Call
:Raise
:AllIn
TexasHoldem.NoOptions
— FunctionNoOptions
The option when a player has no options (e.g., they are all-in).
TexasHoldem.CheckRaiseFold
— FunctionCheckRaiseFold
The option when a player is only able to check, raise, or fold.
TexasHoldem.CallRaiseFold
— FunctionCallRaiseFold
The option when a player is only able to call, raise, or fold.
TexasHoldem.CallAllInFold
— FunctionCallAllInFold
The option when a player is only able to call, raise all-in, or fold.
TexasHoldem.CallFold
— FunctionCallFold
The option when a player is only able to call or fold.
TexasHoldem.get_options
— Functionget_options(game[, current_player])
get_options(game, player)
Retuns the Options
available to player player
for the given game (state) game
.
Action and Options symbols
The name
property of an Action
object ((action::Action).name
) is a Symbol
that can be only one of:
:Fold
:Check
:Call
:Raise
:AllIn
The name
property of an Options
object ((action::Action).name
) is a Symbol
that can be only one of:
:NoOptions
:CheckRaiseFold
:CallRaiseFold
:CallAllInFold
:CallFold
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.
Training
There are additional functionalities added for training purposes
TexasHoldem.recreate_game
— Functionrecreate_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.