commit b308f34b33bc41aadf2d4604d8a79db5ef9744a4
parent bb87174441bf388dba334992ac37eed981b07cbc
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Mon, 11 Dec 2023 22:49:46 -0500
cleanup
Diffstat:
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/pkg/web/handlers/poker/poker.go b/pkg/web/handlers/poker/poker.go
@@ -101,6 +101,11 @@ type PokerStandingPlayer struct {
LastActionTS time.Time
}
+// Return either or not a player is eligible to play a game
+func (p *PokerStandingPlayer) isEligible() bool {
+ return p != nil && p.Cash >= BigBlindBet
+}
+
func (p *PokerStandingPlayer) getDisplayCash(g *PokerGame) int {
if g.Ongoing != nil {
if op := g.Ongoing.GetPlayer(p.Username); op != nil {
@@ -400,7 +405,7 @@ func NewOngoing(g *PokerGame) *Ongoing {
players := make([]*PokerPlayer, 0)
g.PlayersMtx.RLock()
for idx, p := range g.Players {
- if p != nil && p.Cash >= BigBlindBet {
+ if p.isEligible() {
players = append(players, &PokerPlayer{PokerStandingPlayer: p, SeatIdx: idx})
}
}
@@ -730,6 +735,7 @@ func dealPlayersCards(g *PokerGame, roomTopic string, seats []Seat, idx *int) {
func dealerThread(db *database.DkfDB, g *PokerGame, roomID string) {
roomTopic := "room_" + roomID
roomLogsTopic := "room_" + roomID + "_logs"
+ bigBlindBet := BigBlindBet
g.incrDealerIdx()
@@ -779,7 +785,7 @@ func dealerThread(db *database.DkfDB, g *PokerGame, roomID string) {
newLogEvent(g, roomLogsTopic, fmt.Sprintf("-- New game --"))
p := g.Ongoing.Players[g.smallBlindIdx]
- bet := BigBlindBet / 2
+ bet := bigBlindBet / 2
p.doBet(bet)
PokerPubSub.Pub(roomTopic, PlayerBetEvent{PlayerSeatIdx: p.SeatIdx, Player: p.Username, Bet: bet, TotalBet: p.Bet, Cash: p.Cash})
newLogEvent(g, roomLogsTopic, fmt.Sprintf("%s small blind %d", p.Username, bet))
@@ -787,7 +793,7 @@ func dealerThread(db *database.DkfDB, g *PokerGame, roomID string) {
time.Sleep(time.Second)
p = g.Ongoing.Players[g.bigBlindIdx]
- bet = BigBlindBet
+ bet = bigBlindBet
p.doBet(bet)
PokerPubSub.Pub(roomTopic, PlayerBetEvent{PlayerSeatIdx: p.SeatIdx, Player: p.Username, Bet: bet, TotalBet: p.Bet, Cash: p.Cash})
newLogEvent(g, roomLogsTopic, fmt.Sprintf("%s big blind %d", p.Username, bet))
@@ -799,7 +805,7 @@ func dealerThread(db *database.DkfDB, g *PokerGame, roomID string) {
// Wait for players to bet/call/check/fold...
time.Sleep(time.Second)
- if waitPlayersActionFn(g, roomID, 2, BigBlindBet) {
+ if waitPlayersActionFn(g, roomID, 2, bigBlindBet) {
goto END
}
@@ -1001,7 +1007,7 @@ func (g *PokerGame) CountEligibleSeated() (count int) {
g.PlayersMtx.RLock()
defer g.PlayersMtx.RUnlock()
for _, p := range g.Players {
- if p != nil && p.Cash >= BigBlindBet {
+ if p.isEligible() {
count++
}
}