dkforest

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

commit 20a7b5445f7e147000e8cabbcc8e667aaf42009e
parent ca0e3f617e2fa1dae432d49798cba5b6ee39036d
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Fri,  8 Dec 2023 16:51:36 -0500

cleanup

Diffstat:
Mpkg/web/handlers/poker/poker.go | 22+++++++++++++---------
1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/pkg/web/handlers/poker/poker.go b/pkg/web/handlers/poker/poker.go @@ -109,6 +109,10 @@ type PokerPlayer struct { Folded bool } +func (p *PokerPlayer) isAllIn() bool { + return p.Cash == 0 +} + func (p *PokerPlayer) doBet(bet int) { p.RoundTotalBet += bet p.Bet += bet @@ -240,7 +244,7 @@ func isRoundSettled(players []*PokerPlayer) bool { } arr := make([]Tmp, 0) for _, p := range players { - arr = append(arr, Tmp{Bet: p.Bet, AllIn: p.Cash == 0, Folded: p.Folded}) + arr = append(arr, Tmp{Bet: p.Bet, AllIn: p.isAllIn(), Folded: p.Folded}) } sort.Slice(arr, func(i, j int) bool { return arr[i].Bet > arr[j].Bet }) b := arr[0].Bet @@ -391,7 +395,7 @@ OUTER: lastRaisePlayerIdx = playerToPlayIdx } player := g.Ongoing.GetPlayer(p.Username) - if player.Folded || player.Cash == 0 { + if player.Folded || player.isAllIn() { continue } evt := PokerWaitTurnEvent{Idx: p.SeatIdx} @@ -414,7 +418,7 @@ OUTER: case evt = <-g.PlayersEventCh: case <-waitCh: // Waited too long, either auto-check or auto-fold - if p.Cash == 0 { // all-in + if p.isAllIn() { break LOOP } if p.Bet < minBet { @@ -474,7 +478,7 @@ OUTER: p.doBet(bet) PokerPubSub.Pub(roomTopic, PlayerBetEvent{PlayerIdx: p.SeatIdx, Player: p.Username, Bet: bet, TotalBet: p.Bet, Cash: p.Cash}) logMsg := fmt.Sprintf("%s call (%d)", p.Username, bet) - if p.Cash == 0 { + if p.isAllIn() { logMsg += " (all-in)" newlyAllInPlayers = append(newlyAllInPlayers, p) } @@ -489,7 +493,7 @@ OUTER: p.doBet(bet) PokerPubSub.Pub(roomTopic, PlayerBetEvent{PlayerIdx: p.SeatIdx, Player: p.Username, Bet: bet, TotalBet: p.Bet, Cash: p.Cash}) logMsg := fmt.Sprintf("%s all-in (%d)", p.Username, bet) - if p.Cash == 0 { + if p.isAllIn() { newlyAllInPlayers = append(newlyAllInPlayers, p) } newLogEvent(g, roomLogsTopic, logMsg) @@ -513,7 +517,7 @@ OUTER: p.doBet(bet) PokerPubSub.Pub(roomTopic, PlayerBetEvent{PlayerIdx: p.SeatIdx, Player: p.Username, Bet: bet, TotalBet: p.Bet, Cash: p.Cash}) logMsg := fmt.Sprintf("%s bet %d", p.Username, bet) - if p.Cash == 0 { + if p.isAllIn() { logMsg += " (all-in)" newlyAllInPlayers = append(newlyAllInPlayers, p) } @@ -646,7 +650,7 @@ func dealerThread(db *database.DkfDB, g *PokerGame, roomID string) { // Deal cards for cardIdx := 1; cardIdx <= NbCardsPerPlayer; cardIdx++ { for _, p := range g.Ongoing.Players { - if p.Cash == 0 { + if p.isAllIn() { continue } seatData := seats[p.SeatIdx] @@ -801,7 +805,7 @@ func processPot(winners []GameResult, mainPot int) (res []PlayerGain) { piece := mainPot res = append(res, PlayerGain{player, piece, groupIdx, handStr}) mainPot -= piece - } else if len(group.Players) == 1 && group.Players[0].Cash == 0 { + } else if len(group.Players) == 1 && group.Players[0].isAllIn() { // Only 1 player win but is all-in player := group.Players[0] piece := player.AllInMaxGain @@ -814,7 +818,7 @@ func processPot(winners []GameResult, mainPot int) (res []PlayerGain) { expectedSplit := mainPot / nbPlayersInGroup allInCount := 0 for _, p := range group.Players { - if p.Cash == 0 { // all-in + if p.isAllIn() { allInCount++ maxGain := p.AllInMaxGain piece := utils.MinInt(maxGain, expectedSplit)