Skip to content

Commit

Permalink
Fix resampling cards
Browse files Browse the repository at this point in the history
  • Loading branch information
charleskawczynski committed Sep 4, 2023
1 parent 9193644 commit a8e74b0
Showing 1 changed file with 27 additions and 20 deletions.
47 changes: 27 additions & 20 deletions src/recreate.jl
Original file line number Diff line number Diff line change
@@ -1,44 +1,51 @@
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
return nothing
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

"""
Expand Down

0 comments on commit a8e74b0

Please sign in to comment.