dkforest

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

commit 2f0eaacda06d93efbf7d8137fef3ef2325d792b2
parent 702f61281731920e0fb7b007afe35f40fdb9cbd8
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Mon, 25 Dec 2023 11:10:43 -0500

cleanup

Diffstat:
Mpkg/web/handlers/poker/poker.go | 30+++++++++++++++---------------
Mpkg/web/handlers/poker/poker_test.go | 6+++---
2 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/pkg/web/handlers/poker/poker.go b/pkg/web/handlers/poker/poker.go @@ -1528,48 +1528,48 @@ func processPot(winners []gameResult, mainPot, pokerTableMinBet database.PokerCh if mainPot == 0 { break } + groupPlayers := group.players + groupPlayersLen := len(groupPlayers) handStr := poker.RankString(group.handScore) isDone = true - if len(group.players) == 1 && group.players[0].getCash() > 0 { + if groupPlayersLen == 1 && groupPlayers[0].getCash() > 0 { // Only 1 player win and is not all-in - player := group.players[0] + player := groupPlayers[0] piece := mainPot res = append(res, newPlayerGain(player, piece, groupIdx, handStr)) mainPot -= piece - } else if len(group.players) == 1 && group.players[0].isAllIn() { + } else if groupPlayersLen == 1 && groupPlayers[0].isAllIn() { // Only 1 player win but is all-in - player := group.players[0] + player := groupPlayers[0] piece := utils.MinInt(player.allInMaxGain, mainPot) res = append(res, newPlayerGain(player, piece, groupIdx, handStr)) mainPot -= piece isDone = false - } else if len(group.players) > 1 { + } else if groupPlayersLen > 1 { // Multiple winners, split pot - nbPlayersInGroup := len(group.players) - expectedSplit := mainPot / database.PokerChip(nbPlayersInGroup) + expectedSplit := mainPot / database.PokerChip(groupPlayersLen) allInCount := 0 - for _, p := range group.players { + for _, p := range groupPlayers { if p.isAllIn() { allInCount++ maxGain := p.allInMaxGain - piece := utils.MinInt(maxGain, expectedSplit) - piece = utils.MinInt(piece, mainPot) + piece := utils.MinInt(maxGain, expectedSplit, mainPot) res = append(res, newPlayerGain(p, piece, groupIdx, handStr)) mainPot -= piece - if nbPlayersInGroup-allInCount > 0 { - expectedSplit = mainPot / database.PokerChip(nbPlayersInGroup-allInCount) + if groupPlayersLen-allInCount > 0 { + expectedSplit = mainPot / database.PokerChip(groupPlayersLen-allInCount) } else { expectedSplit = mainPot } } } // If everyone in the group was all-in, we need to evaluate the next group as well - if allInCount == nbPlayersInGroup { + if allInCount == groupPlayersLen { isDone = false continue } - piece := mainPot / database.PokerChip(nbPlayersInGroup-allInCount) - for _, p := range group.players { + piece := mainPot / database.PokerChip(groupPlayersLen-allInCount) + for _, p := range groupPlayers { if p.getCash() > 0 { piece = utils.MinInt(piece, mainPot) res = append(res, newPlayerGain(p, piece, groupIdx, handStr)) diff --git a/pkg/web/handlers/poker/poker_test.go b/pkg/web/handlers/poker/poker_test.go @@ -2,13 +2,13 @@ package poker import ( "dkforest/pkg/database" - "dkforest/pkg/utils" + "dkforest/pkg/utils/rwmtx" "github.com/stretchr/testify/assert" "testing" ) -func n(v uint64) utils.RWMtx[database.PokerChip] { - return utils.NewRWMtx[database.PokerChip](database.PokerChip(v)) +func n(v uint64) rwmtx.RWMtxUInt64[database.PokerChip] { + return rwmtx.RWMtxUInt64[database.PokerChip]{rwmtx.New(database.PokerChip(v))} } func Test_sortGameResults(t *testing.T) {