commit 982be4076c0ade231f9eb0379070ac127213ad28
parent 20a7b5445f7e147000e8cabbcc8e667aaf42009e
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Fri, 8 Dec 2023 18:00:37 -0500
fix split pot
Diffstat:
2 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/pkg/web/handlers/poker/poker.go b/pkg/web/handlers/poker/poker.go
@@ -808,7 +808,7 @@ func processPot(winners []GameResult, mainPot int) (res []PlayerGain) {
} 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
+ piece := utils.MinInt(player.AllInMaxGain, mainPot)
res = append(res, PlayerGain{player, piece, groupIdx, handStr})
mainPot -= piece
isDone = false
@@ -822,6 +822,7 @@ func processPot(winners []GameResult, mainPot int) (res []PlayerGain) {
allInCount++
maxGain := p.AllInMaxGain
piece := utils.MinInt(maxGain, expectedSplit)
+ piece = utils.MinInt(piece, mainPot)
res = append(res, PlayerGain{p, piece, groupIdx, handStr})
mainPot -= piece
if nbPlayersInGroup-allInCount > 0 {
@@ -839,6 +840,7 @@ func processPot(winners []GameResult, mainPot int) (res []PlayerGain) {
piece := mainPot / (nbPlayersInGroup - allInCount)
for _, p := range group.Players {
if p.Cash > 0 {
+ piece = utils.MinInt(piece, mainPot)
res = append(res, PlayerGain{p, piece, groupIdx, handStr})
mainPot -= piece
}
diff --git a/pkg/web/handlers/poker/poker_test.go b/pkg/web/handlers/poker/poker_test.go
@@ -80,6 +80,18 @@ func Test_processPot(t *testing.T) {
assert.Equal(t, 8, res[0].Gain)
assert.Equal(t, 8, res[1].Gain)
assert.Equal(t, 7, res[2].Gain)
+
+ p1 = &PokerPlayer{Cash: 0, RoundTotalBet: 900, AllInMaxGain: 1560, Username: "p1"}
+ p2 = &PokerPlayer{Cash: 0, RoundTotalBet: 640, AllInMaxGain: 1300, Username: "p2"}
+ arr = []GameResult{
+ {1, []*PokerPlayer{p2}},
+ {2, []*PokerPlayer{p1}},
+ }
+ sortGameResults(arr)
+ res = processPot(arr, 1560)
+ assert.Equal(t, 2, len(res))
+ assert.Equal(t, 1300, res[0].Gain)
+ assert.Equal(t, 260, res[1].Gain)
}
func Test_isRoundSettled(t *testing.T) {