dkforest

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

commit b3cc25500f573b8cd0975ecf3289ca5739330adf
parent ae0e5e66a48c5f804c937382899b3070ca36fa28
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Mon, 11 Dec 2023 22:11:47 -0500

cleanup

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

diff --git a/pkg/web/handlers/poker/poker.go b/pkg/web/handlers/poker/poker.go @@ -261,6 +261,24 @@ func (g *Ongoing) GetPlayerBySeatIdx(seatIdx int) *PokerPlayer { return nil } +func (g *Ongoing) CountCanVotePlayers() (nbCanVote int) { + for _, p := range g.Players { + if !p.Folded.Load() && p.Cash > 0 { + nbCanVote++ + } + } + return +} + +func (g *Ongoing) CountAlivePlayers() (playerAlive int) { + for _, p := range g.Players { + if !p.Folded.Load() { + playerAlive++ + } + } + return +} + func (g *Ongoing) GetPlayer(player string) *PokerPlayer { for _, p := range g.Players { if p.Username == player { @@ -439,27 +457,16 @@ func setWaitTurn(g *PokerGame, roomTopic string, seatIdx int) { func waitPlayersActionFn(g *PokerGame, roomID string, skip, minBet int) bool { roomTopic := "room_" + roomID roomLogsTopic := "room_" + roomID + "_logs" - playerAlive := 0 dealerSeatIdx := int(g.DealerSeatIdx.Load()) dealerIdx := g.Ongoing.getPlayerIdxBySeatIdx(dealerSeatIdx) playerToPlayIdx := (dealerIdx + skip) % len(g.Ongoing.Players) lastRaisePlayerIdx := -1 newlyAllInPlayers := make([]*PokerPlayer, 0) - // Avoid asking for actions if only 1 player can do so (because others are all-in) - nbCanVote := 0 - for _, p := range g.Ongoing.Players { - if !p.Folded.Load() && p.Cash > 0 { - nbCanVote++ - } - } - - for _, p := range g.Ongoing.Players { - if !p.Folded.Load() { - playerAlive++ - } - } + playerAlive := g.Ongoing.CountAlivePlayers() + // Avoid asking for actions if only 1 player can do so (because others are all-in) + nbCanVote := g.Ongoing.CountCanVotePlayers() if nbCanVote == 0 { // TODO: Refund bets goto END1