commit de214c2b9e1e42300d02b591432dbccbdb359c17
parent dfea1b8cadfefa10ab0cb5d9c288bdac4b828bfd
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Wed, 13 Dec 2023 15:31:35 -0500
use table minimum bet setting
Diffstat:
1 file changed, 22 insertions(+), 21 deletions(-)
diff --git a/pkg/web/handlers/poker/poker.go b/pkg/web/handlers/poker/poker.go
@@ -32,7 +32,6 @@ const DealSpacing = 55
const DealerStackX = 250
const DealerStackY = 30
const NbCardsPerPlayer = 2
-const BigBlindBet = 20
type Poker struct {
sync.Mutex
@@ -45,16 +44,17 @@ func NewPoker() *Poker {
return p
}
-func (p *Poker) GetOrCreateGame(roomID string, pokerTableID int64) *PokerGame {
+func (p *Poker) GetOrCreateGame(roomID string, pokerTableID int64, pokerTableMinBet int) *PokerGame {
p.Lock()
defer p.Unlock()
g, found := p.games[roomID]
if !found {
g = &PokerGame{
- PokerTableID: pokerTableID,
- PlayersEventCh: make(chan PlayerEvent),
- Players: make([]*PokerStandingPlayer, NbPlayers),
- DealerSeatIdx: atomic.Int32{},
+ PokerTableID: pokerTableID,
+ PokerTableMinBet: pokerTableMinBet,
+ PlayersEventCh: make(chan PlayerEvent),
+ Players: make([]*PokerStandingPlayer, NbPlayers),
+ DealerSeatIdx: atomic.Int32{},
}
g.DealerSeatIdx.Store(-1)
p.games[roomID] = g
@@ -106,8 +106,8 @@ type PokerStandingPlayer struct {
}
// 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) isEligible(pokerTableMinBet int) bool {
+ return p != nil && p.Cash >= pokerTableMinBet
}
func (p *PokerStandingPlayer) getDisplayCash(g *PokerGame) int {
@@ -152,15 +152,16 @@ type PlayerCard struct {
type PokerGame struct {
sync.Mutex
- PokerTableID int64
- PlayersEventCh chan PlayerEvent
- Players []*PokerStandingPlayer
- PlayersMtx sync.RWMutex
- Ongoing *Ongoing
- DealerSeatIdx atomic.Int32
- smallBlindIdx int
- bigBlindIdx int
- IsGameStarted atomic.Bool
+ PokerTableID int64
+ PokerTableMinBet int
+ PlayersEventCh chan PlayerEvent
+ Players []*PokerStandingPlayer
+ PlayersMtx sync.RWMutex
+ Ongoing *Ongoing
+ DealerSeatIdx atomic.Int32
+ smallBlindIdx int
+ bigBlindIdx int
+ IsGameStarted atomic.Bool
}
type GameResult struct {
@@ -431,7 +432,7 @@ func NewOngoing(g *PokerGame) *Ongoing {
players := make([]*PokerPlayer, 0)
g.PlayersMtx.RLock()
for idx, p := range g.Players {
- if p.isEligible() {
+ if p.isEligible(g.PokerTableMinBet) {
players = append(players, &PokerPlayer{PokerStandingPlayer: p, SeatIdx: idx})
}
}
@@ -767,7 +768,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
+ bigBlindBet := g.PokerTableMinBet
g.incrDealerIdx()
@@ -1070,7 +1071,7 @@ func (g *PokerGame) CountEligibleSeated() (count int) {
g.PlayersMtx.RLock()
defer g.PlayersMtx.RUnlock()
for _, p := range g.Players {
- if p.isEligible() {
+ if p.isEligible(g.PokerTableMinBet) {
count++
}
}
@@ -1948,7 +1949,7 @@ func PokerHandler(c echo.Context) error {
roomUserTopic := "room_" + roomID + "_" + authUser.Username.String()
send := func(s string) { _, _ = c.Response().Write([]byte(s)) }
- g := PokerInstance.GetOrCreateGame(roomID, pokerTable.ID)
+ g := PokerInstance.GetOrCreateGame(roomID, pokerTable.ID, int(pokerTable.MinBet))
quit := hutils.CloseSignalChan(c)
hutils.SetStreamingHeaders(c)