commit 86a3998038a3f4b7e421850b5f591a4e1037da01
parent 9f81888e7a59be6f8be250e81bf2c51ae2574ec8
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Thu, 7 Dec 2023 17:28:21 -0500
split pot and all-in
Diffstat:
1 file changed, 21 insertions(+), 5 deletions(-)
diff --git a/pkg/web/handlers/poker/poker.go b/pkg/web/handlers/poker/poker.go
@@ -768,12 +768,28 @@ func processPot(winners []GameResult, nbPlayers, mainPot int) (winnersStr, winne
isDone = false
} else if len(group.Players) > 1 {
// Multiple winners, split pot
- // TODO: handle all-ins
- nb := len(group.Players)
- piece := mainPot / nb // TODO: fix this
+ nbPlayersInGroup := len(group.Players)
+ allInCount := 0
for _, p := range group.Players {
- p.Cash += piece
- winnersStr += p.Username
+ if p.Cash == 0 { // all-in
+ allInCount++
+ maxGain := p.RoundTotalBet * nbPlayers
+ piece := maxGain / nbPlayersInGroup
+ p.Cash += piece
+ mainPot -= piece
+ winnersStr += p.Username
+ }
+ }
+ if allInCount == nbPlayersInGroup {
+ isDone = false
+ continue
+ }
+ piece := mainPot / nbPlayersInGroup // TODO: fix this
+ for _, p := range group.Players {
+ if p.Cash > 0 {
+ p.Cash += piece
+ winnersStr += p.Username
+ }
}
winnerHand = poker.RankString(group.HandScore)
}