dkforest

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

commit 2b33e20e80d44d1a0fec74c3da36e2d288305c4f
parent c756e0528bf74694fcd1b4921e1e6b4ef733abef
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Sun, 17 Dec 2023 01:40:35 -0500

make accessor for bet

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

diff --git a/pkg/web/handlers/poker/poker.go b/pkg/web/handlers/poker/poker.go @@ -125,6 +125,8 @@ type PokerPlayer struct { countChancesToAction int } +func (p *PokerPlayer) GetBet() database.PokerChip { return p.Bet } + func (p *PokerPlayer) isAllIn() bool { return p.Cash == 0 } @@ -134,7 +136,7 @@ func (p *PokerPlayer) doBet(db *database.DkfDB, bet database.PokerChip, pokerTab p.RoundTotalBet += bet p.Bet += bet p.Cash -= bet - PokerPubSub.Pub(roomTopic, PlayerBetEvent{PlayerSeatIdx: p.SeatIdx, Player: p.Username, Bet: bet, TotalBet: p.Bet, Cash: p.Cash}) + PokerPubSub.Pub(roomTopic, PlayerBetEvent{PlayerSeatIdx: p.SeatIdx, Player: p.Username, Bet: bet, TotalBet: p.GetBet(), Cash: p.Cash}) } type PlayerCard struct { @@ -312,7 +314,7 @@ func isRoundSettled(players []*PokerPlayer) bool { } arr := make([]Tmp, 0) for _, p := range players { - arr = append(arr, Tmp{Bet: p.Bet, AllIn: p.isAllIn(), Folded: p.Folded.Load()}) + arr = append(arr, Tmp{Bet: p.GetBet(), AllIn: p.isAllIn(), Folded: p.Folded.Load()}) } sort.Slice(arr, func(i, j int) bool { return arr[i].Bet > arr[j].Bet }) b := arr[0].Bet @@ -561,7 +563,7 @@ RoundIsSettledLoop: PokerPubSub.Pub(roomUserTopic, PokerYourTurnEvent{}) doTimeout := func() int { - if p.Bet < minBet { + if p.GetBet() < minBet { foldPlayer(p) newLogEvent(g, roomLogsTopic, fmt.Sprintf("%s auto fold", pUsername)) @@ -597,8 +599,8 @@ RoundIsSettledLoop: } doCheck := func() int { - if p.Bet < minBet { - msg := fmt.Sprintf("Need to bet %d", minBet-p.Bet) + if p.GetBet() < minBet { + msg := fmt.Sprintf("Need to bet %d", minBet-p.GetBet()) PokerPubSub.Pub(roomUserTopic, ErrorMsgEvent{Message: msg}) return continueGetPlayerEventLoop } @@ -607,7 +609,7 @@ RoundIsSettledLoop: } doCall := func() int { - bet := utils.MinInt(minBet-p.Bet, p.Cash) + bet := utils.MinInt(minBet-p.GetBet(), p.Cash) if bet == 0 { newLogEvent(g, roomLogsTopic, fmt.Sprintf("%s check", pUsername)) } else { @@ -624,10 +626,10 @@ RoundIsSettledLoop: doAllIn := func() int { bet := p.Cash - if (p.Bet + bet) > minBet { + if (p.GetBet() + bet) > minBet { lastRaisePlayerIdx = playerToPlayIdx } - minBet = utils.MaxInt(p.Bet+bet, minBet) + minBet = utils.MaxInt(p.GetBet()+bet, minBet) p.doBet(db, bet, g.PokerTableID, roomTopic) logMsg := fmt.Sprintf("%s all-in (%d)", pUsername, bet) if p.isAllIn() { @@ -641,13 +643,13 @@ RoundIsSettledLoop: pokerTableMinBet := g.PokerTableMinBet bet := evt.Bet // Ensure the player cannot bet below the table minimum bet (amount of the big blind) - if p.Bet+bet != minBet && bet < pokerTableMinBet { + if p.GetBet()+bet != minBet && bet < pokerTableMinBet { msg := fmt.Sprintf("Bet (%d) is too low. Must bet at least %d", bet, pokerTableMinBet) PokerPubSub.Pub(roomUserTopic, ErrorMsgEvent{Message: msg}) return continueGetPlayerEventLoop } - if (p.Bet + bet) < minBet { - msg := fmt.Sprintf("Bet (%d) is too low. Must bet at least %d", bet, minBet-p.Bet) + if (p.GetBet() + bet) < minBet { + msg := fmt.Sprintf("Bet (%d) is too low. Must bet at least %d", bet, minBet-p.GetBet()) PokerPubSub.Pub(roomUserTopic, ErrorMsgEvent{Message: msg}) return continueGetPlayerEventLoop } @@ -656,10 +658,10 @@ RoundIsSettledLoop: PokerPubSub.Pub(roomUserTopic, ErrorMsgEvent{Message: msg}) return continueGetPlayerEventLoop } - if (p.Bet + bet) > minBet { + if (p.GetBet() + bet) > minBet { lastRaisePlayerIdx = playerToPlayIdx } - minBet = utils.MaxInt(p.Bet+bet, minBet) + minBet = utils.MaxInt(p.GetBet()+bet, minBet) p.doBet(db, bet, g.PokerTableID, roomTopic) logMsg := fmt.Sprintf("%s bet %d", pUsername, bet) if p.isAllIn() { @@ -807,7 +809,7 @@ RoundIsSettled: for _, p := range newlyAllInPlayers { maxGain := mainPot for _, op := range g.Ongoing.Players { - maxGain += utils.MinInt(op.Bet, p.Bet) + maxGain += utils.MinInt(op.GetBet(), p.GetBet()) } p.AllInMaxGain = maxGain } @@ -817,10 +819,10 @@ RoundIsSettled: if !isPreFlop && playerAlive == 1 { newArray := make([]*PokerPlayer, len(g.Ongoing.Players)) copy(newArray, g.Ongoing.Players) - sort.Slice(newArray, func(i, j int) bool { return newArray[i].Bet > newArray[j].Bet }) + sort.Slice(newArray, func(i, j int) bool { return newArray[i].GetBet() > newArray[j].GetBet() }) firstPlayer := newArray[0] secondPlayer := newArray[1] - diff := firstPlayer.Bet - secondPlayer.Bet + diff := firstPlayer.GetBet() - secondPlayer.GetBet() _ = db.PokerTableAccountRefundPartialBet(firstPlayer.UserID, g.PokerTableID, diff) firstPlayer.Bet -= diff firstPlayer.Cash += diff @@ -828,7 +830,7 @@ RoundIsSettled: // Transfer players bets into the main pot for _, p := range g.Ongoing.Players { - mainPot += p.Bet + mainPot += p.GetBet() _ = db.PokerTableAccountResetAmountBet(p.UserID, g.PokerTableID) p.Bet = 0 } @@ -1116,7 +1118,7 @@ func applyGains(db *database.DkfDB, g *PokerGame, playersGain []PlayerGain, main // No winners, refund bets for _, op := range g.Ongoing.Players { _ = tx.PokerTableAccountRefundBet(op.UserID, g.PokerTableID) - op.Cash += op.Bet + op.Cash += op.GetBet() op.Bet = 0 } } @@ -1818,8 +1820,8 @@ func drawSeatsStyle(authUser *database.User, g *PokerGame) string { html += `#seat` + itoa(i+1) + ` .inner:before { content: "` + pUsername.String() + `"; }` html += `#seat` + itoa(i+1) + `_cash:before { content: "` + itoa2(p.Cash) + `"; }` if g.Ongoing != nil { - if op := g.Ongoing.GetPlayer(pUsername); op != nil && op.Bet > 0 { - html += `#seat` + itoa(i+1) + `Pot:before { content: "` + itoa2(op.Bet) + `"; }` + if op := g.Ongoing.GetPlayer(pUsername); op != nil && op.GetBet() > 0 { + html += `#seat` + itoa(i+1) + `Pot:before { content: "` + itoa2(op.GetBet()) + `"; }` } } } else {