TexasHoldem.jl

A package for simulating multi-player no-limit texas holdem games
Author charleskawczynski
Popularity
4 Stars
Updated Last
1 Year Ago
Started In
March 2021

TexasHoldem.jl

Docs Build docs build
Documentation dev
GHA CI gha ci
Code Coverage codecov
Bors enabled bors

A package for simulating no-limit Texas Holdem Poker. Install with

(@v1.x) pkg> add TexasHoldem

Playing

A single game can be played with play! and tournament-style game with tournament!:

using TexasHoldem
play!(configure_game()) # play 1 game
tournament!(configure_game()) # play until 1 player remains

Creating your own bot

Four methods (variants of player_option!) need to be defined to create and play your own bot:

using TexasHoldem
import TexasHoldem
TH = TexasHoldem

struct MyBot <: AbstractAI end

function TH.player_option!(game::Game, player::Player{MyBot}, ::CheckRaiseFold)
    # options are:
    #    check!(game, player)
    #    raise!(game, player, amt::Float64)
    #    raise_all_in!(game, player)
    #    fold!(game, player)
    if rand() < 0.5
        check!(game, player)
    else
        amt = Int(round(rand()*bank_roll(player), digits=0))
        amt = TH.bound_raise(game.table, player, amt) # to properly bound raise amount
        raise_to!(game, player, amt)
    end
end
function TH.player_option!(game::Game, player::Player{MyBot}, ::CallRaiseFold)
    # options are:
    #    call!(game, player)
    #    raise!(game, player, amt::Float64)
    #    raise_all_in!(game, player)
    #    fold!(game, player)
    if rand() < 0.5
        if rand() < 0.5 # Call
            call!(game, player)
        else # re-raise
            amt = Int(round(rand()*bank_roll(player), digits=0))
            amt = TH.bound_raise(game.table, player, amt) # to properly bound raise amount
            raise_to!(game, player, amt)
        end
    else
        fold!(game, player)
    end
end
function TH.player_option!(game::Game, player::Player{MyBot}, ::CallAllInFold)
    # options are:
    #    call!(game, player)
    #    raise_all_in!(game, player)
    #    fold!(game, player)
    if rand() < 0.5
        if rand() < 0.5 # Call
            call!(game, player)
        else # re-raise
            raise_all_in!(game, player)
        end
    else
        fold!(game, player)
    end
end
function TH.player_option!(game::Game, player::Player{MyBot}, ::CallFold)
    # options are:
    #    call!(game, player)
    #    fold!(game, player)
    if rand() < 0.5
        call!(game, player)
    else
        fold!(game, player)
    end
end

# Heads-up against the MyBot!
tournament!(Game((Player(Human(), 1), Player(MyBot(), 2))))

Related packages

Package Development status Purpose
PlayingCards.jl Perhaps stable Representing cards
PokerHandEvaluator.jl Perhaps stable Comparing any two 5-7 card hands
TexasHoldem.jl Likely changes needed Simulating multi-player games of TexasHoldem
PokerBots.jl very early development Battling bots with prescribed (or learned) strategies
PokerGUI.jl very early development Visualizing TexasHoldem games via a GUI

Used By Packages

No packages found.