commit 3500050ac18e593a0a2d1338caed500f97dcced5
parent a3a9e539e82569d23cd2907a3d7ff3093cca3a91
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Tue, 19 Dec 2023 11:49:21 -0500
cleanup
Diffstat:
1 file changed, 21 insertions(+), 21 deletions(-)
diff --git a/pkg/web/handlers/poker/poker.go b/pkg/web/handlers/poker/poker.go
@@ -125,7 +125,7 @@ func (e playerEvent) getAction() PlayerAction {
var PokerInstance = newPoker()
-type Ongoing struct {
+type ongoingGame struct {
logEvents utils.RWMtx[[]LogEvent]
deck []string
players []*pokerPlayer
@@ -227,7 +227,7 @@ type playerCard struct {
type PokerGame struct {
Players utils.RWMtx[[]*seatedPlayer]
- ongoing *Ongoing
+ ongoing *ongoingGame
db *database.DkfDB
roomID RoomID
pokerTableID int64
@@ -285,19 +285,19 @@ func (g *PokerGame) sendPlayerEvent(evt playerEvent) {
}
}
-func (g *Ongoing) isHeadsUpGame() bool {
+func (g *ongoingGame) isHeadsUpGame() bool {
return len(g.players) == 2 // https://en.wikipedia.org/wiki/Heads-up_poker
}
-func (g *Ongoing) getMainPot() (out database.PokerChip) {
+func (g *ongoingGame) getMainPot() (out database.PokerChip) {
return database.PokerChip(g.mainPot.Load())
}
-func (g *Ongoing) setMainPot(v database.PokerChip) {
+func (g *ongoingGame) setMainPot(v database.PokerChip) {
g.mainPot.Store(uint64(v))
}
-func (g *Ongoing) computeWinners() (winner []gameResult) {
+func (g *ongoingGame) computeWinners() (winner []gameResult) {
countAlive := 0
var lastAlive *pokerPlayer
for _, p := range g.players {
@@ -366,24 +366,24 @@ func sortGameResults(arr []gameResult) {
sort.Slice(arr, func(i, j int) bool { return arr[i].handScore < arr[j].handScore })
}
-func (g *Ongoing) addEvent(evts ...PokerEvent) {
+func (g *ongoingGame) addEvent(evts ...PokerEvent) {
g.events.With(func(events *[]PokerEvent) {
*events = append(*events, evts...)
})
}
-func (g *Ongoing) getDeckStr() string {
+func (g *ongoingGame) getDeckStr() string {
return strings.Join(g.deck, "")
}
-func (g *Ongoing) GetDeckHash() string {
+func (g *ongoingGame) GetDeckHash() string {
return utils.MD5([]byte(g.getDeckStr()))
}
-// Get the player index in Ongoing.Players from a seat index (index in PokerGame.Players)
+// Get the player index in ongoingGame.Players from a seat index (index in PokerGame.Players)
// [nil p1 nil nil p2 nil] -> PokerGame.Players
-// [p1 p2] -> Ongoing.Players
-func (g *Ongoing) getPlayerBySeatIdx(seatIdx int) (*pokerPlayer, int) {
+// [p1 p2] -> ongoingGame.Players
+func (g *ongoingGame) getPlayerBySeatIdx(seatIdx int) (*pokerPlayer, int) {
for idx, p := range g.players {
if p.seatIdx == seatIdx {
return p, idx
@@ -392,7 +392,7 @@ func (g *Ongoing) getPlayerBySeatIdx(seatIdx int) (*pokerPlayer, int) {
return nil, -1
}
-func (g *Ongoing) countCanBetPlayers() (nbCanBet int) {
+func (g *ongoingGame) countCanBetPlayers() (nbCanBet int) {
for _, p := range g.players {
if p.canBet() {
nbCanBet++
@@ -401,7 +401,7 @@ func (g *Ongoing) countCanBetPlayers() (nbCanBet int) {
return
}
-func (g *Ongoing) countAlivePlayers() (playerAlive int) {
+func (g *ongoingGame) countAlivePlayers() (playerAlive int) {
for _, p := range g.players {
if !p.folded.Load() {
playerAlive++
@@ -410,7 +410,7 @@ func (g *Ongoing) countAlivePlayers() (playerAlive int) {
return
}
-func (g *Ongoing) getPlayer(userID database.UserID) *pokerPlayer {
+func (g *ongoingGame) getPlayer(userID database.UserID) *pokerPlayer {
for _, p := range g.players {
if p.userID == userID {
return p
@@ -560,7 +560,7 @@ func generateDeck() []string {
return deck
}
-func newOngoing(g *PokerGame) *Ongoing {
+func newOngoing(g *PokerGame) *ongoingGame {
players := make([]*pokerPlayer, 0)
g.Players.RWith(func(gPlayers *[]*seatedPlayer) {
for _, p := range *gPlayers {
@@ -569,7 +569,7 @@ func newOngoing(g *PokerGame) *Ongoing {
}
}
})
- return &Ongoing{
+ return &ongoingGame{
deck: generateDeck(),
players: players,
waitTurnEvent: utils.NewRWMtx(PokerWaitTurnEvent{Idx: -1}),
@@ -993,14 +993,14 @@ RoundIsSettled:
}
// Reset all players bets, and return the sum of it
-func resetPlayersBet(ongoing *Ongoing) (sum database.PokerChip) {
+func resetPlayersBet(ongoing *ongoingGame) (sum database.PokerChip) {
for _, p := range ongoing.players {
sum += p.resetBet()
}
return
}
-func refundUncalledBet(db *database.DkfDB, ongoing *Ongoing, pokerTableID int64, roomTopic string) {
+func refundUncalledBet(db *database.DkfDB, ongoing *ongoingGame, pokerTableID int64, roomTopic string) {
newArray := make([]*pokerPlayer, len(ongoing.players))
copy(newArray, ongoing.players)
sort.Slice(newArray, func(i, j int) bool { return newArray[i].getBet() > newArray[j].getBet() })
@@ -1117,7 +1117,7 @@ func dealPlayersCards(g *PokerGame, seats []Seat, idx *int) {
}
}
-func computeAllInMaxGain(ongoing *Ongoing, newlyAllInPlayers []*pokerPlayer, mainPot database.PokerChip) {
+func computeAllInMaxGain(ongoing *ongoingGame, newlyAllInPlayers []*pokerPlayer, mainPot database.PokerChip) {
for _, p := range newlyAllInPlayers {
maxGain := mainPot
for _, op := range ongoing.players {
@@ -1267,7 +1267,7 @@ func autoUnsitInactivePlayers(g *PokerGame) {
}
// Returns either or not a seated player should be booted out of the table.
-func playerShouldBeBooted(p *seatedPlayer, ongoing *Ongoing, pokerTableMinBet database.PokerChip) (playerShallBeBooted bool) {
+func playerShouldBeBooted(p *seatedPlayer, ongoing *ongoingGame, pokerTableMinBet database.PokerChip) (playerShallBeBooted bool) {
if p == nil {
return false
}