dkforest

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

commit 49bd3b17baec3287f1bb6ee8504b89ee5c92963a
parent fb5187b60a77a69804df3cdde60a72ab919cc678
Author: n0tr1v <n0tr1v@protonmail.com>
Date:   Sun, 17 Dec 2023 06:45:35 -0500

cleanup

Diffstat:
Mpkg/web/handlers/poker/poker.go | 25++++++++++++-------------
1 file changed, 12 insertions(+), 13 deletions(-)

diff --git a/pkg/web/handlers/poker/poker.go b/pkg/web/handlers/poker/poker.go @@ -186,8 +186,6 @@ type PokerGame struct { PlayersMtx sync.RWMutex Ongoing *Ongoing DealerSeatIdx atomic.Int32 - smallBlindIdx int - bigBlindIdx int IsGameStarted atomic.Bool } @@ -365,7 +363,7 @@ func isRoundSettled(players []*PokerPlayer) bool { return true } -func (g *PokerGame) incrDealerIdx() { +func (g *PokerGame) incrDealerIdx() (smallBlindIdx, bigBlindIdx int) { ongoing := g.Ongoing nbPlayers := len(ongoing.Players) dealerSeatIdx := g.DealerSeatIdx.Load() @@ -379,8 +377,9 @@ func (g *PokerGame) incrDealerIdx() { } g.DealerSeatIdx.Store(dealerSeatIdx) startIDx := utils.Ternary(ongoing.isHeadsUpGame(), 0, 1) - g.smallBlindIdx = (dealerIdx + startIDx) % nbPlayers - g.bigBlindIdx = (dealerIdx + startIDx + 1) % nbPlayers + smallBlindIdx = (dealerIdx + startIDx) % nbPlayers + bigBlindIdx = (dealerIdx + startIDx + 1) % nbPlayers + return } func (g *PokerGame) UnSitPlayer(username database.Username) error { @@ -963,8 +962,6 @@ func dealerThread(g *PokerGame) { ongoing := g.Ongoing isHeadsUpGame := ongoing.isHeadsUpGame() - g.incrDealerIdx() - seats := []Seat{ {Top: 55, Left: 610, Top2: 55 + 5, Left2: 610 + 5, Angle: "-95deg"}, {Top: 175, Left: 620, Top2: 175 + 5, Left2: 620 + 3, Angle: "-80deg"}, @@ -1007,13 +1004,15 @@ func dealerThread(g *PokerGame) { ongoing.CommunityCards = append(ongoing.CommunityCards, card) } + sbIdx, bbIdx := g.incrDealerIdx() + PokerPubSub.Pub(roomTopic, GameStartedEvent{DealerSeatIdx: int(g.DealerSeatIdx.Load())}) g.newLogEvent(fmt.Sprintf("-- New game --")) - applySmallBlindBet(g, bigBlindBet) + applySmallBlindBet(g, bigBlindBet, sbIdx) time.Sleep(time.Second) - applyBigBlindBet(g, bigBlindBet) + applyBigBlindBet(g, bigBlindBet, bbIdx) time.Sleep(time.Second) // Deal players cards @@ -1093,12 +1092,12 @@ END: g.IsGameStarted.Store(false) } -func applySmallBlindBet(g *PokerGame, bigBlindBet database.PokerChip) { - applyBlindBet(g, g.smallBlindIdx, bigBlindBet/2, "small blind") +func applySmallBlindBet(g *PokerGame, bigBlindBet database.PokerChip, sbIdx int) { + applyBlindBet(g, sbIdx, bigBlindBet/2, "small blind") } -func applyBigBlindBet(g *PokerGame, bigBlindBet database.PokerChip) { - applyBlindBet(g, g.bigBlindIdx, bigBlindBet, "big blind") +func applyBigBlindBet(g *PokerGame, bigBlindBet database.PokerChip, bbIdx int) { + applyBlindBet(g, bbIdx, bigBlindBet, "big blind") } func applyBlindBet(g *PokerGame, playerIdx int, bet database.PokerChip, name string) {