dkforest

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

commit 9dcce8a6f64be76b8d1654f40dfc1e14827c062d
parent cce8980ebd5d93f023732a9d42f5a40cd4542465
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Mon, 25 Dec 2023 14:19:41 -0500

cleanup

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

diff --git a/pkg/web/handlers/poker/poker.go b/pkg/web/handlers/poker/poker.go @@ -135,13 +135,13 @@ type ongoingGame struct { events rwmtx.RWMtxSlice[PokerEvent] waitTurnEvent rwmtx.RWMtx[PokerWaitTurnEvent] autoActionEvent rwmtx.RWMtx[AutoActionEvent] + mainPot rwmtx.RWMtx[database.PokerChip] minBet rwmtx.RWMtx[database.PokerChip] minRaise rwmtx.RWMtx[database.PokerChip] playerToPlay rwmtx.RWMtx[database.UserID] hasBet rwmtx.RWMtx[bool] players pokerPlayers createdAt time.Time - mainPot atomic.Uint64 communityCards []string deck []string } @@ -395,14 +395,6 @@ func (g *ongoingGame) isHeadsUpGame() bool { return len(g.players) == 2 // https://en.wikipedia.org/wiki/Heads-up_poker } -func (g *ongoingGame) getMainPot() (out database.PokerChip) { - return database.PokerChip(g.mainPot.Load()) -} - -func (g *ongoingGame) setMainPot(v database.PokerChip) { - g.mainPot.Store(uint64(v)) -} - func (g *ongoingGame) computeWinners() (winner []gameResult) { return computeWinners(g.players, g.communityCards) } @@ -1095,7 +1087,7 @@ RoundIsSettled: time.Sleep(animationTime) - mainPot := ongoing.getMainPot() + mainPot := ongoing.mainPot.Get() // Calculate what is the max gain all-in players can make computeAllInMaxGain(ongoing, newlyAllInPlayers, mainPot) @@ -1109,7 +1101,7 @@ RoundIsSettled: mainPot += resetPlayersBet(ongoing) PubSub.Pub(roomTopic, PokerMainPotUpdatedEvent{MainPot: mainPot}) - ongoing.setMainPot(mainPot) + ongoing.mainPot.Set(mainPot) g.ongoing.hasBet.Set(false) return playerAlive <= 1 @@ -1352,11 +1344,11 @@ func dealerThread(g *Game, eligiblePlayers seatedPlayers) { END: winners := ongoing.computeWinners() - mainPot := ongoing.getMainPot() + mainPot := ongoing.mainPot.Get() playersGain, rake := processPot(winners, mainPot, bigBlindBet, collectRake, len(ongoing.players)) winnersStr, winnerHand := applyGains(g, playersGain, mainPot, rake) - ongoing.setMainPot(0) + ongoing.mainPot.Set(0) PubSub.Pub(roomTopic, GameIsDoneEvent{Winner: winnersStr, WinnerHand: winnerHand}) g.newLogEvent(fmt.Sprintf("-- Game ended --")) @@ -1751,7 +1743,7 @@ func buildMainPotHtml(g *Game) string { html := `<div id="mainPot"></div>` mainPot := uint64(0) if ongoing != nil { - mainPot = uint64(ongoing.getMainPot()) + mainPot = uint64(ongoing.mainPot.Get()) } html += `<style>#mainPot:before { content: "Pot: ` + itoa1(mainPot) + `"; }</style>` return html