From a8e74b09df49bc425308467020c40911a48e8caa Mon Sep 17 00:00:00 2001 From: Charles Kawczynski Date: Sun, 3 Sep 2023 17:15:49 -0700 Subject: [PATCH] Fix resampling cards --- src/recreate.jl | 47 +++++++++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/src/recreate.jl b/src/recreate.jl index 08256a1d..bb700e08 100644 --- a/src/recreate.jl +++ b/src/recreate.jl @@ -1,32 +1,31 @@ +table_card_inds(::PreFlop) = ntuple(_->i, 5) +table_card_inds(::Flop) = (4, 5) +table_card_inds(::Turn) = (5,) -function resample_unobserved_table_cards!(table::Table, round::PreFlop) - for c in table.cards - PlayingCards.restore!(table.deck, c) - end - @inbounds for j in 1:5 - table.cards[j] = SB.sample!(table.deck) +function restore_unobserved_table_cards!(table::Table, inds) + @inbounds for i in inds + PlayingCards.restore!(table.deck, table.cards[i]) end return nothing end -function resample_unobserved_table_cards!(table::Table, round::Flop) - @inbounds PlayingCards.restore!(table.deck, table.cards[4]) - @inbounds PlayingCards.restore!(table.deck, table.cards[5]) - @inbounds table.cards[4] = SB.sample!(table.deck) - @inbounds table.cards[5] = SB.sample!(table.deck) - return nothing -end -function resample_unobserved_table_cards!(table::Table, round::Turn) - @inbounds PlayingCards.restore!(table.deck, table.cards[5]) - @inbounds table.cards[5] = SB.sample!(table.deck) + +function resample_unobserved_table_cards!(table::Table, inds) + @inbounds for i in inds + player.cards[i] = SB.sample!(table.deck) + end return nothing end -resample_unobserved_table_cards!(table::Table, round::River) = nothing -function resample_player_cards!(table::Table, player::Player) +function restore_player_cards!(table::Table, player::Player) @assert has_cards(player) for c in player.cards PlayingCards.restore!(table.deck, c) end + return nothing +end + +function resample_player_cards!(table::Table, player::Player) + @assert !has_cards(player) @inbounds for j in 1:2 player.cards[j] = SB.sample!(table.deck) end @@ -34,11 +33,19 @@ function resample_player_cards!(table::Table, player::Player) end function resample_cards!(game::Game, player::Player) table = game.table - for opponent in players_at_table(table) + players = players_at_table(table) + tci = table_card_inds(table.round) + restore_unobserved_table_cards!(table, tci) + for opponent in players + seat_number(opponent) == seat_number(player) && continue + restore_player_cards!(table, opponent) + end + + resample_unobserved_table_cards!(table, tci) + for opponent in players seat_number(opponent) == seat_number(player) && continue resample_player_cards!(table, opponent) end - resample_unobserved_table_cards!(table, table.round) end """