commit fabd2992d17083f44ad7380f226ad88e51f32b4f
parent 6c854f13203338f7d36f35cd9870fd54f2e70214
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Mon, 25 Dec 2023 12:16:31 -0500
cleanup
Diffstat:
2 files changed, 39 insertions(+), 33 deletions(-)
diff --git a/pkg/web/handlers/poker/poker.go b/pkg/web/handlers/poker/poker.go
@@ -1521,41 +1521,36 @@ func processPot(winners []gameResult, mainPot, pokerTableMinBet database.PokerCh
mainPot -= rake
}
- if len(winners) == 1 && len(winners[0].players) == 1 {
- // Everyone fold but 1 player
- player := winners[0].players[0]
- piece := mainPot
- res = append(res, newPlayerGain(player, piece, 0, "Only player alive"))
- mainPot -= piece
- } else {
- for groupIdx, group := range winners {
- if mainPot == 0 {
- break
- }
- groupPlayers := group.players
- groupPlayersLen := len(groupPlayers)
- handStr := poker.RankString(group.handScore)
- // Multiple winners, split pot
- calcExpectedSplit := func(mainPot database.PokerChip, allInCount int) database.PokerChip {
- return mainPot / utils.MaxInt(database.PokerChip(groupPlayersLen-allInCount), 1)
- }
- allInCount := 0
- expectedSplit := calcExpectedSplit(mainPot, allInCount)
- for _, p := range groupPlayers {
- piece := utils.MinInt(p.maxGain(mainPot), expectedSplit)
- res = append(res, newPlayerGain(p, piece, groupIdx, handStr))
- mainPot -= piece
- if p.isAllIn() {
- allInCount++
- expectedSplit = calcExpectedSplit(mainPot, allInCount)
- }
- }
- // If everyone in the group was all-in, we need to evaluate the next group as well
- if allInCount == groupPlayersLen {
- continue
- }
+ for groupIdx, group := range winners {
+ if mainPot == 0 {
break
}
+ groupPlayers := group.players
+ groupPlayersLen := len(groupPlayers)
+ handStr := poker.RankString(group.handScore)
+ if len(winners) == 1 && len(winners[0].players) == 1 {
+ handStr = "Only player alive"
+ }
+ // Multiple winners, split pot
+ calcExpectedSplit := func(mainPot database.PokerChip, allInCount int) database.PokerChip {
+ return mainPot / utils.MaxInt(database.PokerChip(groupPlayersLen-allInCount), 1)
+ }
+ allInCount := 0
+ expectedSplit := calcExpectedSplit(mainPot, allInCount)
+ for _, p := range groupPlayers {
+ piece := utils.MinInt(p.maxGain(mainPot), expectedSplit)
+ res = append(res, newPlayerGain(p, piece, groupIdx, handStr))
+ mainPot -= piece
+ if p.isAllIn() {
+ allInCount++
+ expectedSplit = calcExpectedSplit(mainPot, allInCount)
+ }
+ }
+ // If everyone in the group was all-in, we need to evaluate the next group as well
+ if allInCount == groupPlayersLen {
+ continue
+ }
+ break
}
// If any remaining "odd chip(s)" distribute them to players.
diff --git a/pkg/web/handlers/poker/poker_test.go b/pkg/web/handlers/poker/poker_test.go
@@ -98,6 +98,17 @@ func Test_processPot(t *testing.T) {
assert.Equal(t, 2, len(res))
assert.Equal(t, database.PokerChip(1300), res[0].Gain)
assert.Equal(t, database.PokerChip(260), res[1].Gain)
+
+ p1 = &PokerPlayer{seatedPlayer: &seatedPlayer{cash: n(1), username: "p1"}, gameBet: 500}
+ arr = []gameResult{
+ {2, []*PokerPlayer{p1}},
+ }
+ sortGameResults(arr)
+ res, _ = processPot(arr, 1000, 20, false, 2)
+ assert.Equal(t, 1, len(res))
+ assert.Equal(t, database.Username("p1"), res[0].Player.username)
+ assert.Equal(t, database.PokerChip(1000), res[0].Gain)
+ assert.Equal(t, "Only player alive", res[0].HandStr)
}
func Test_isRoundSettled(t *testing.T) {