dkforest

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

commit e19a567017ed88c5c01ea1cfc9c072fa4f34d191
parent f12091b0a94adb64da4d1f3ac11e20b45eaf1399
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Mon, 18 Dec 2023 21:18:49 -0500

cleanup

Diffstat:
Mpkg/web/handlers/poker/poker.go | 32++++++++++++++++++--------------
1 file changed, 18 insertions(+), 14 deletions(-)

diff --git a/pkg/web/handlers/poker/poker.go b/pkg/web/handlers/poker/poker.go @@ -870,21 +870,11 @@ RoundIsSettled: mainPot := ongoing.getMainPot() // Calculate what is the max gain all-in players can make - computeAllInMaxGain(g, newlyAllInPlayers, mainPot) + computeAllInMaxGain(ongoing, newlyAllInPlayers, mainPot) // Always refund the difference between the first-biggest bet and the second-biggest bet. // We refund the "uncalled bet" so that it does not go in the main pot and does not get raked. - newArray := make([]*PokerPlayer, len(ongoing.Players)) - copy(newArray, ongoing.Players) - sort.Slice(newArray, func(i, j int) bool { return newArray[i].GetBet() > newArray[j].GetBet() }) - firstPlayer := newArray[0] - secondPlayer := newArray[1] - diff := firstPlayer.GetBet() - secondPlayer.GetBet() - if diff > 0 { - firstPlayer.refundPartialBet(db, pokerTableID, diff) - PokerPubSub.Pub(roomTopic, RedrawSeatsEvent{}) - time.Sleep(time.Second) - } + refundUncalledBet(db, ongoing, pokerTableID, roomTopic) // Transfer players bets into the main pot for _, p := range ongoing.Players { @@ -898,6 +888,20 @@ RoundIsSettled: return playerAlive <= 1 } +func refundUncalledBet(db *database.DkfDB, ongoing *Ongoing, pokerTableID int64, roomTopic string) { + newArray := make([]*PokerPlayer, len(ongoing.Players)) + copy(newArray, ongoing.Players) + sort.Slice(newArray, func(i, j int) bool { return newArray[i].GetBet() > newArray[j].GetBet() }) + firstPlayer := newArray[0] + secondPlayer := newArray[1] + diff := firstPlayer.GetBet() - secondPlayer.GetBet() + if diff > 0 { + firstPlayer.refundPartialBet(db, pokerTableID, diff) + PokerPubSub.Pub(roomTopic, RedrawSeatsEvent{}) + time.Sleep(time.Second) + } +} + type Seat struct { Top int Left int @@ -968,10 +972,10 @@ func dealPlayersCards(g *PokerGame, seats []Seat, idx *int) { } } -func computeAllInMaxGain(g *PokerGame, newlyAllInPlayers []*PokerPlayer, mainPot database.PokerChip) { +func computeAllInMaxGain(ongoing *Ongoing, newlyAllInPlayers []*PokerPlayer, mainPot database.PokerChip) { for _, p := range newlyAllInPlayers { maxGain := mainPot - for _, op := range g.Ongoing.Players { + for _, op := range ongoing.Players { maxGain += utils.MinInt(op.GetBet(), p.GetBet()) } p.AllInMaxGain = maxGain