From 5ec18b2d4f9f973808c7239984b2f7040ef1ed7d Mon Sep 17 00:00:00 2001 From: Charles Kawczynski Date: Sun, 3 Sep 2023 17:15:49 -0700 Subject: [PATCH 1/2] Fix resampling cards --- src/recreate.jl | 63 +++++++++++++++++++++++++++++-------------------- 1 file changed, 38 insertions(+), 25 deletions(-) diff --git a/src/recreate.jl b/src/recreate.jl index 08256a1d..9061d583 100644 --- a/src/recreate.jl +++ b/src/recreate.jl @@ -1,44 +1,57 @@ +table_card_inds(::PreFlop) = ntuple(i->i, 5) +table_card_inds(::Flop) = (4, 5) +table_card_inds(::Turn) = (5,) +table_card_inds(::River) = () -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 + table.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) - @assert has_cards(player) - for c in player.cards +function restore_player_cards!(table::Table, player::Player) + has_cards(player) || return false + for (i, c) in enumerate(player.cards) PlayingCards.restore!(table.deck, c) + player.cards[i] = joker end - @inbounds for j in 1:2 - player.cards[j] = SB.sample!(table.deck) + return true +end + +function resample_player_cards!(table::Table, player::Player) + @assert !has_cards(player) + @inbounds for i in 1:2 + player.cards[i] = SB.sample!(table.deck) end return nothing end function resample_cards!(game::Game, player::Player) table = game.table - for opponent in players_at_table(table) - seat_number(opponent) == seat_number(player) && continue + players = players_at_table(table) + tci = table_card_inds(table.round) + player_cards_to_resample = BitVector(ntuple(i->false, length(players))) + restore_unobserved_table_cards!(table, tci) + for opponent in players + sn = seat_number(opponent) + sn == seat_number(player) && continue + player_cards_to_resample[sn] = restore_player_cards!(table, opponent) + end + + resample_unobserved_table_cards!(table, tci) + for opponent in players + sn = seat_number(opponent) + sn == seat_number(player) && continue + player_cards_to_resample[sn] || continue resample_player_cards!(table, opponent) end - resample_unobserved_table_cards!(table, table.round) end """ From 3e767e352d351544389fb1e682ecb65886f9f304 Mon Sep 17 00:00:00 2001 From: Charles Kawczynski Date: Sun, 3 Sep 2023 17:27:25 -0700 Subject: [PATCH 2/2] Bump patch version --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 0506f435..030d8d19 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "TexasHoldem" uuid = "6cef90fc-eb55-4a2a-97d0-7ecce2b738fe" authors = ["Charles Kawczynski "] -version = "0.4.3" +version = "0.4.4" [deps] Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"