dkforest

A forum and chat platform (onion)
git clone https://git.dasho.dev/n0tr1v/dkforest.git
Log | Files | Refs | LICENSE

commit 64cd122b95f009b2e45922c708806cbb76bf1e2f
parent af9d05daeaa8146c205e35118cb4586ee009fdaf
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Thu,  7 Dec 2023 16:12:34 -0500

cleanup

Diffstat:
Mpkg/web/handlers/poker/poker.go | 40+++++++++++++++++++++-------------------
1 file changed, 21 insertions(+), 19 deletions(-)

diff --git a/pkg/web/handlers/poker/poker.go b/pkg/web/handlers/poker/poker.go @@ -97,13 +97,20 @@ type PokerStandingPlayer struct { } type PokerPlayer struct { - Username string - Bet int - Cash int - SeatIdx int // 0 indexed - Cards []PlayerCard - CardsMtx sync.RWMutex - Folded bool + Username string + RoundTotalBet int + Bet int + Cash int + SeatIdx int // 0 indexed + Cards []PlayerCard + CardsMtx sync.RWMutex + Folded bool +} + +func (p *PokerPlayer) doBet(bet int) { + p.RoundTotalBet += bet + p.Bet += bet + p.Cash -= bet } type PlayerCard struct { @@ -427,13 +434,9 @@ OUTER: } else if evt.Call { bet := minBet - p.Bet if p.Cash < bet { - bet = p.Cash - p.Bet += bet - p.Cash = 0 - // All in + p.doBet(p.Cash) // All in } else { - p.Bet += bet - p.Cash -= bet + p.doBet(bet) } PokerPubSub.Pub(roomTopic, PlayerBetEvent{PlayerIdx: p.SeatIdx, Player: p.Username, Bet: bet, TotalBet: p.Bet, Cash: p.Cash}) newLogEvent(g, roomLogsTopic, fmt.Sprintf("%s call", p.Username)) @@ -454,8 +457,7 @@ OUTER: lastRisePlayerIdx = p.SeatIdx } minBet = p.Bet + bet - p.Bet += bet - p.Cash -= bet + p.doBet(bet) PokerPubSub.Pub(roomTopic, PlayerBetEvent{PlayerIdx: p.SeatIdx, Player: p.Username, Bet: bet, TotalBet: p.Bet, Cash: p.Cash}) newLogEvent(g, roomLogsTopic, fmt.Sprintf("%s bet %d", p.Username, bet)) @@ -566,8 +568,7 @@ func dealerThread(db *database.DkfDB, g *PokerGame, roomID string) { p := g.Ongoing.Players[g.smallBlindIdx] bet := SmallBlindBet - p.Bet += bet - p.Cash -= bet + p.doBet(bet) PokerPubSub.Pub(roomTopic, PlayerBetEvent{PlayerIdx: p.SeatIdx, Player: p.Username, Bet: bet, TotalBet: p.Bet, Cash: p.Cash}) newLogEvent(g, roomLogsTopic, fmt.Sprintf("%s small blind %d", p.Username, bet)) @@ -575,8 +576,7 @@ func dealerThread(db *database.DkfDB, g *PokerGame, roomID string) { p = g.Ongoing.Players[g.bigBlindIdx] bet = BigBlindBet - p.Bet += bet - p.Cash -= bet + p.doBet(bet) PokerPubSub.Pub(roomTopic, PlayerBetEvent{PlayerIdx: p.SeatIdx, Player: p.Username, Bet: bet, TotalBet: p.Bet, Cash: p.Cash}) newLogEvent(g, roomLogsTopic, fmt.Sprintf("%s big blind %d", p.Username, bet)) @@ -714,6 +714,8 @@ END: winnerHand = poker.RankString(winners[0].HandScore) winners[0].Players[0].Cash += mainPot winnersStr += winners[0].Players[0].Username + //} else if len(winners[0].Players) == 1 && winners[0].Players[0].Cash == 0 { + // Only 1 player win but is all-in } else if len(winners[0].Players) > 1 { // Multiple winners, split pot nb := len(winners[0].Players)