dkforest

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

commit cce8980ebd5d93f023732a9d42f5a40cd4542465
parent 1e9c468c5090e9d1b131dc1be1663d2cc9efa03c
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Mon, 25 Dec 2023 14:17:01 -0500

cleanup

Diffstat:
Mpkg/web/handlers/poker/poker.go | 52++++++++++++++++++++++++----------------------------
1 file changed, 24 insertions(+), 28 deletions(-)

diff --git a/pkg/web/handlers/poker/poker.go b/pkg/web/handlers/poker/poker.go @@ -135,8 +135,8 @@ type ongoingGame struct { events rwmtx.RWMtxSlice[PokerEvent] waitTurnEvent rwmtx.RWMtx[PokerWaitTurnEvent] autoActionEvent rwmtx.RWMtx[AutoActionEvent] - MinBet rwmtx.RWMtx[database.PokerChip] - MinRaise 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 @@ -249,28 +249,28 @@ func (g *Game) IsYourTurn(player *PokerPlayer) (out bool) { func (g *Game) CanCheck(player *PokerPlayer) (out bool) { if g.ongoing != nil { - return player.bet.Get() == g.ongoing.MinBet.Get() + return player.bet.Get() == g.ongoing.minBet.Get() } return } func (g *Game) CanFold(player *PokerPlayer) (out bool) { if g.ongoing != nil { - return player.bet.Get() < g.ongoing.MinBet.Get() + return player.bet.Get() < g.ongoing.minBet.Get() } return } func (g *Game) MinBet() (out database.PokerChip) { if g.ongoing != nil { - return g.ongoing.MinBet.Get() + return g.ongoing.minBet.Get() } return } func (p *Game) MinRaise() (out database.PokerChip) { if p.ongoing != nil { - return p.ongoing.MinRaise.Get() + return p.ongoing.minRaise.Get() } return } @@ -399,10 +399,6 @@ func (g *ongoingGame) getMainPot() (out database.PokerChip) { return database.PokerChip(g.mainPot.Load()) } -func (g *ongoingGame) getMinRaise() (out database.PokerChip) { - return g.MinRaise.Get() -} - func (g *ongoingGame) setMainPot(v database.PokerChip) { g.mainPot.Store(uint64(v)) } @@ -785,7 +781,7 @@ func doUnsit(g *Game, p *PokerPlayer, playerAlive *int) int { func doTimeout(g *Game, p *PokerPlayer, playerAlive *int) int { pUsername := p.username - if p.GetBet() < g.ongoing.MinBet.Get() { + if p.GetBet() < g.ongoing.minBet.Get() { foldPlayer(g, p) p.status.Set("fold") g.newLogEvent(fmt.Sprintf("%s auto fold", pUsername)) @@ -803,7 +799,7 @@ func doTimeout(g *Game, p *PokerPlayer, playerAlive *int) int { } func doCheck(g *Game, p *PokerPlayer) int { - minBet := g.ongoing.MinBet.Get() + minBet := g.ongoing.minBet.Get() if p.GetBet() < minBet { msg := fmt.Sprintf("Need to bet %d", minBet-p.GetBet()) PubSub.Pub(g.roomID.UserTopic(p.userID), NewErrorMsgEvent(msg)) @@ -817,7 +813,7 @@ func doCheck(g *Game, p *PokerPlayer) int { func doFold(g *Game, p *PokerPlayer, playerAlive *int) int { roomUserTopic := g.roomID.UserTopic(p.userID) - if p.GetBet() == g.ongoing.MinBet.Get() { + if p.GetBet() == g.ongoing.minBet.Get() { msg := fmt.Sprintf("Cannot fold if there is no bet; check") PubSub.Pub(roomUserTopic, NewErrorMsgEvent(msg)) return doCheck(g, p) @@ -837,7 +833,7 @@ func doFold(g *Game, p *PokerPlayer, playerAlive *int) int { func doCall(g *Game, p *PokerPlayer, newlyAllInPlayers *[]*PokerPlayer, lastBetPlayerIdx *int, playerToPlayIdx int) int { pUsername := p.username - bet := utils.MinInt(g.ongoing.MinBet.Get()-p.GetBet(), p.getCash()) + bet := utils.MinInt(g.ongoing.minBet.Get()-p.GetBet(), p.getCash()) if bet == 0 { return doCheck(g, p) } else if bet == p.cash.Get() { @@ -854,13 +850,13 @@ func doCall(g *Game, p *PokerPlayer, func doAllIn(g *Game, p *PokerPlayer, newlyAllInPlayers *[]*PokerPlayer, lastBetPlayerIdx *int, playerToPlayIdx int) int { bet := p.getCash() - minBet := g.ongoing.MinBet.Get() + minBet := g.ongoing.minBet.Get() if (p.GetBet() + bet) > minBet { *lastBetPlayerIdx = playerToPlayIdx - g.ongoing.MinRaise.Set(bet) + g.ongoing.minRaise.Set(bet) PubSub.Pub(g.roomID.Topic(), PokerMinRaiseUpdatedEvent{MinRaise: bet}) } - g.ongoing.MinBet.Set(utils.MaxInt(p.GetBet()+bet, minBet)) + g.ongoing.minBet.Set(utils.MaxInt(p.GetBet()+bet, minBet)) p.doBetAndNotif(g.db, g.pokerTableID, bet, g.roomID.Topic()) logMsg := fmt.Sprintf("%s all-in (%d)", p.username, bet) if p.isAllIn() { @@ -873,15 +869,15 @@ func doAllIn(g *Game, p *PokerPlayer, func doRaise(g *Game, p *PokerPlayer, newlyAllInPlayers *[]*PokerPlayer, lastBetPlayerIdx *int, playerToPlayIdx int) int { - return doBet(g, p, newlyAllInPlayers, lastBetPlayerIdx, playerToPlayIdx, g.ongoing.MinRaise.Get()) + return doBet(g, p, newlyAllInPlayers, lastBetPlayerIdx, playerToPlayIdx, g.ongoing.minRaise.Get()) } func doBet(g *Game, p *PokerPlayer, newlyAllInPlayers *[]*PokerPlayer, lastBetPlayerIdx *int, playerToPlayIdx int, evtBet database.PokerChip) int { roomTopic := g.roomID.Topic() roomUserTopic := g.roomID.UserTopic(p.userID) - minBet := g.ongoing.MinBet.Get() - minRaise := g.ongoing.MinRaise.Get() + minBet := g.ongoing.minBet.Get() + minRaise := g.ongoing.minRaise.Get() playerBet := p.bet.Get() // Player's chips already on the table callDelta := minBet - playerBet // Chips missing to equalize the minBet bet := evtBet + callDelta // Amount of chips player need to put on the table to make the raise @@ -898,11 +894,11 @@ func doBet(g *Game, p *PokerPlayer, } *lastBetPlayerIdx = playerToPlayIdx PubSub.Pub(g.roomID.Topic(), PokerMinRaiseUpdatedEvent{MinRaise: evtBet}) - g.ongoing.MinRaise.Set(evtBet) - g.ongoing.MinBet.Set(playerTotalBet) + g.ongoing.minRaise.Set(evtBet) + g.ongoing.minBet.Set(playerTotalBet) p.doBetAndNotif(g.db, g.pokerTableID, bet, roomTopic) - g.newLogEvent(fmt.Sprintf("%s %s %d", p.username, betLbl, g.ongoing.MinRaise.Get())) + g.newLogEvent(fmt.Sprintf("%s %s %d", p.username, betLbl, g.ongoing.minRaise.Get())) if p.hasChecked { p.status.Set("check-" + betLbl) p.hasChecked = false @@ -984,8 +980,8 @@ func handlePlayerActionEvent(g *Game, p *PokerPlayer, func execBettingRound(g *Game, skip int, minBet database.PokerChip) bool { roomID := g.roomID roomTopic := roomID.Topic() - g.ongoing.MinBet.Set(minBet) - g.ongoing.MinRaise.Set(g.PokerTableMinBet) + g.ongoing.minBet.Set(minBet) + g.ongoing.minRaise.Set(g.PokerTableMinBet) PubSub.Pub(roomTopic, PokerMinRaiseUpdatedEvent{MinRaise: g.PokerTableMinBet}) db := g.db ongoing := g.ongoing @@ -1032,7 +1028,7 @@ RoundIsSettledLoop: continue AllPlayersLoop } - minBet = g.ongoing.MinBet.Get() + minBet = g.ongoing.minBet.Get() PubSub.Pub(roomUserTopic, RefreshButtonsEvent{}) @@ -1290,7 +1286,7 @@ func dealerThread(g *Game, eligiblePlayers seatedPlayers) { applyBigBlindBet(g, bigBlindBet, bbIdx) time.Sleep(animationTime) g.ongoing.hasBet.Set(true) - g.ongoing.MinRaise.Set(g.PokerTableMinBet) + g.ongoing.minRaise.Set(g.PokerTableMinBet) // Deal players cards dealPlayersCards(g, seats, &idx) @@ -1766,7 +1762,7 @@ func buildMinRaiseHtml(g *Game) string { html := `<div id="minRaise"></div>` minRaise := uint64(0) if ongoing != nil { - minRaise = uint64(ongoing.getMinRaise()) + minRaise = uint64(ongoing.minRaise.Get()) } html += `<style>#minRaise:before { content: "Min raise: ` + itoa1(minRaise) + `"; }</style>` return html