diff --git a/perf/benchmark.jl b/perf/benchmark.jl index 219852e9..4b848b10 100644 --- a/perf/benchmark.jl +++ b/perf/benchmark.jl @@ -16,25 +16,12 @@ TH.player_option!(game::Game, player::Player{BotCheckCall}, ::CallFold) = call!( players() = ntuple(i->(Player(BotCheckCall(), i)), 4) -# use a counter to avoid benchmarking -# the creation of players and games: -const cntr = Int[1] -function do_work!(games) - with_logger(NullLogger()) do - play!(games[cntr[1]]) - cntr[]+=1 - end - return nothing -end - -games = map(x->Game(players()), 1:100_000); -trial = @benchmark do_work!($games) -show(stdout, MIME("text/plain"), trial) - -# Also benchmark including the -# creation of players and games: +# It's not easy to benchmark games without +# also benchmarking the creation/allocation +# of games. We previously did, and they're +# very close in benchmark times. function do_work!() - with_logger(NullLogger()) do + Logging.with_logger(Logging.NullLogger()) do play!(Game(players())) end return nothing diff --git a/perf/jet.jl b/perf/jet.jl index d52e3a3a..99b38652 100644 --- a/perf/jet.jl +++ b/perf/jet.jl @@ -22,7 +22,6 @@ end # Make sure it runs without errors game = Game(players();logger=TH.ByPassLogger()) -println("------------ about to do work") do_work!(game) import JET diff --git a/src/table.jl b/src/table.jl index 7e4cd815..c32b315c 100644 --- a/src/table.jl +++ b/src/table.jl @@ -50,7 +50,7 @@ buttons(b::Buttons) = ( b.first_to_act, ) -mutable struct Table{P,L} +mutable struct Table{P, L, TM} deck::PlayingCards.Deck players::P cards::Union{Nothing,Tuple{<:Card,<:Card,<:Card,<:Card,<:Card}} @@ -60,7 +60,7 @@ mutable struct Table{P,L} buttons::Buttons current_raise_amt::Float64 initial_round_raise_amt::Float64 - transactions::TransactionManager + transactions::TM winners::Winners play_out_game::Bool n_max_actions::Int @@ -106,20 +106,18 @@ function Table(; dealer_id = default_dealer_id(), current_raise_amt = Float64(0), initial_round_raise_amt = blinds.small, - transactions = nothing, + transactions = TransactionManager(players), winners = Winners(), play_out_game = false, logger = StandardLogger(), ) P = typeof(players) - if transactions == nothing - transactions = TransactionManager(players) - end buttons = Buttons(dealer_id, players) n_max_actions = compute_n_max_actions(players, blinds.big) @cdebug logger "n_max_actions = $n_max_actions" L = typeof(logger) - return Table{P,L}(deck, + TM = typeof(transactions) + return Table{P, L, TM}(deck, players, cards, blinds, diff --git a/src/transactions.jl b/src/transactions.jl index d99ee922..84e8d801 100644 --- a/src/transactions.jl +++ b/src/transactions.jl @@ -23,10 +23,10 @@ cap(sp::SidePot) = sp.cap Handle pots and side pots among multiple players. """ -struct TransactionManager - sorted_players::Vector{Player} +struct TransactionManager{SP} + sorted_players::SP initial_brs::Vector{Float64} - pot_id::Union{Nothing,Vector{Int}} + pot_id::Vector{Int} side_pots::Vector{SidePot} unsorted_to_sorted_map::Vector{Int} end @@ -51,9 +51,10 @@ function TransactionManager(players) unsorted_to_sorted_map = collect(map(players) do player findfirst(seat_number.(sorted_players) .== seat_number(player)) end) - side_pots = [SidePot(sn, 0, cap_i) for (cap_i, sn, amt) in zip(cap, seat_number.(sorted_players), bank_roll.(sorted_players))] + side_pots = [SidePot(seat_number(sp), 0, cap_i) for (cap_i, sp) in zip(cap, sorted_players)] - TransactionManager( + SP = typeof(sorted_players) + TransactionManager{SP}( sorted_players, deepcopy(collect(bank_roll.(players))), Int[1],