commit eb67d2942324330e005e7e818b500c29e6b34ec6
parent 6b5aa8c48c1910a10986f9bd7db30665328f91d1
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Mon, 18 Dec 2023 23:10:44 -0500
cleanup
Diffstat:
1 file changed, 17 insertions(+), 12 deletions(-)
diff --git a/pkg/web/handlers/poker/poker.go b/pkg/web/handlers/poker/poker.go
@@ -152,6 +152,11 @@ func (p *PokerPlayer) GetBet() (out database.PokerChip) {
return
}
+func (p *PokerPlayer) canBet() bool {
+ return !p.Folded.Load() && !p.isAllIn()
+
+}
+
func (p *PokerPlayer) isAllIn() bool {
return p.GetCash() == 0
}
@@ -333,7 +338,7 @@ func (g *Ongoing) getPlayerBySeatIdx(seatIdx int) (*PokerPlayer, int) {
func (g *Ongoing) countCanBetPlayers() (nbCanVote int) {
for _, p := range g.Players {
- if !p.Folded.Load() && !p.isAllIn() {
+ if p.canBet() {
nbCanVote++
}
}
@@ -594,6 +599,15 @@ func foldPlayer(g *PokerGame, p *PokerPlayer) {
g.Ongoing.AddEvent(evt1, evt2)
}
+func doUnsit(g *PokerGame, p *PokerPlayer, playerAlive *int) int {
+ *playerAlive = g.Ongoing.CountAlivePlayers()
+ if *playerAlive == 1 {
+ p.countChancesToAction--
+ return breakRoundIsSettledLoop
+ }
+ return continueGetPlayerEventLoop
+}
+
func doTimeout(g *PokerGame, p *PokerPlayer, minBet *database.PokerChip, playerAlive *int) int {
pUsername := p.Username
if p.GetBet() < *minBet {
@@ -610,15 +624,6 @@ func doTimeout(g *PokerGame, p *PokerPlayer, minBet *database.PokerChip, playerA
return breakGetPlayerEventLoop
}
-func doUnsit(g *PokerGame, p *PokerPlayer, playerAlive *int) int {
- *playerAlive = g.Ongoing.CountAlivePlayers()
- if *playerAlive == 1 {
- p.countChancesToAction--
- return breakRoundIsSettledLoop
- }
- return continueGetPlayerEventLoop
-}
-
func doFold(g *PokerGame, p *PokerPlayer, playerAlive *int) int {
foldPlayer(g, p)
g.newLogEvent(fmt.Sprintf("%s fold", p.Username))
@@ -818,7 +823,7 @@ RoundIsSettledLoop:
if lastRaisePlayerIdx == -1 {
lastRaisePlayerIdx = playerToPlayIdx
}
- if p.Folded.Load() || p.isAllIn() {
+ if !p.canBet() {
continue AllPlayersLoop
}
@@ -988,7 +993,7 @@ func dealPlayersCards(g *PokerGame, seats []Seat, idx *int) {
for cardIdx := 1; cardIdx <= NbCardsPerPlayer; cardIdx++ {
for _, p := range ongoing.Players {
pUsername := p.Username
- if p.Folded.Load() || p.isAllIn() {
+ if !p.canBet() {
continue
}
roomUserTopic := roomID.UserTopic(pUsername)