Skip to content

charleskawczynski/PokerBots.jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PokerBots.jl

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

An experimental package for developing poker bots

Example

Here, we'll battle 4 bots (two RandomBots with prob = 0.6, and two with prob = 0.5):

Click to expand and see the bot definitions
struct BotRandom <: AbstractAI
    prob::Float64
end
function TH.player_option!(game::Game, player::Player{BotRandom}, ::CheckRaiseFold)
    prob = TH.life_form(player).prob
    if rand() < prob; 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{BotRandom}, ::CallRaiseFold)
    prob = TH.life_form(player).prob
    if rand() < 1-prob
        if rand() < prob; 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{BotRandom}, ::CallAllInFold)
    prob = TH.life_form(player).prob
    if rand() < 1-prob
        if rand() < prob; call!(game, player)
        else; raise_all_in!(game, player) # re-raise
        end
    else
        fold!(game, player)
    end
end
function TH.player_option!(game::Game, player::Player{BotRandom}, ::CallFold)
    prob = TH.life_form(player).prob
    if rand() < 1-prob; call!(game, player)
    else; fold!(game, player)
    end
end

Once the bots have been defined, battles can be configured in this repo as follows (see test/runtests.jl for the full implementation):

    n_tournaments = 50
    bots = (
        PB.BotRandom(0.4),
        PB.BotRandom(0.4),
        PB.BotRandom(0.6),
        PB.BotRandom(0.6),
    )
    @time stats, n_games = PB.battle!(n_tournaments, bots...)
    plot_stats(stats, n_games)

Here's the results. At 50 tournaments it's (sometimes) difficult to see which strategy is doing better

At 500 tournaments, it's clear which strategy is winning out

Note that there is variance between the two exact same strategies-- that's the "luck" of the game! But it's clear that the exact same strategies have the same asymptotic behavior.

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

About

An experimental package for developing poker bots

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages