Skip to content

Commit

Permalink
Merge pull request #231 from charleskawczynski/ck/fix_resampling
Browse files Browse the repository at this point in the history
Fix resampling cards
  • Loading branch information
charleskawczynski authored Sep 4, 2023
2 parents 9193644 + 3e767e3 commit e209337
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "TexasHoldem"
uuid = "6cef90fc-eb55-4a2a-97d0-7ecce2b738fe"
authors = ["Charles Kawczynski <kawczynski.charles@gmail.com>"]
version = "0.4.3"
version = "0.4.4"

[deps]
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
Expand Down
63 changes: 38 additions & 25 deletions src/recreate.jl
Original file line number Diff line number Diff line change
@@ -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

"""
Expand Down

2 comments on commit e209337

@charleskawczynski
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/90758

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.4.4 -m "<description of version>" e20933742cf595b4f0a93f3ee85da922773b058d
git push origin v0.4.4

Please sign in to comment.