Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve log for winning hands #90

Merged
merged 1 commit into from
Jun 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/table.jl
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ function Base.iterate(ct::CircleTable{P},
end

show_cards(table::Table, player::Player{Human}) = player.cards
show_cards(table::Table, player::Player{LF}) where {LF <: AbstractAI} = "??"
show_cards(table::Table, player::Player{LF}) where {LF <: AbstractAI} = "(??,??)"

#####
##### Deal
Expand Down
28 changes: 23 additions & 5 deletions src/transactions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ struct TransactionManager
initial_brs::Vector{Float64}
pot_id::Union{Nothing,Vector{Int}}
side_pots::Vector{SidePot}
unsorted_to_sorted_map::Vector{Int}
end

function Base.show(io::IO, tm::TransactionManager, include_type = true)
Expand All @@ -47,11 +48,17 @@ function TransactionManager(players)
end
end

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))]

TransactionManager(
sorted_players,
deepcopy(collect(bank_roll.(players))),
Int[1],
[SidePot(sn, 0, cap_i) for (cap_i, sn, amt) in zip(cap, seat_number.(sorted_players), bank_roll.(sorted_players))],
side_pots,
unsorted_to_sorted_map,
)
end
amount(tm::TransactionManager) = amount(tm.side_pots[tm.pot_id[1]])
Expand Down Expand Up @@ -240,14 +247,25 @@ function distribute_winnings!(players, tm::TransactionManager, table_cards)
tm.side_pots[j].amt = 0 # empty out distributed winnings
end
end
for (i, (player, initial_br, player_winnings)) in enumerate(zip(players, tm.initial_brs, side_pot_winnings))
for (player, initial_br, player_winnings) in zip(players, tm.initial_brs, side_pot_winnings)
∑spw = sum(player_winnings)
if !(∑spw ≈ 0)
winning_hand = nameof(typeof(winning_hands[i]))
ssn = tm.unsorted_to_sorted_map[seat_number(player)]
if ∑spw ≈ 0
if active(player)
hand = hand_evals_sorted[ssn].fhe
hand_name = nameof(typeof(hand_type(hand)))
bc = best_cards(hand)
f_str = folded(player) ? " (folded)" : ""
@info "$(name(player)) loses$f_str \$$(pot_investment(player)) with $bc ($hand_name)!"
end
else
hand = hand_evals_sorted[ssn].fhe
hand_name = nameof(typeof(hand_type(hand)))
bc = best_cards(hand)
amt_contributed = initial_br - bank_roll(player)
@debug "$(name(player))'s side-pot wins: \$$(player_winnings)!"
prof = ∑spw-amt_contributed
@info "$(name(player)) wins \$$∑spw (\$$prof profit) with $(winning_hand)!"
@info "$(name(player)) wins \$$∑spw (\$$prof profit) with $bc ($hand_name)!"
player.bank_roll += ∑spw
end
end
Expand Down