From dc41b3599625f811299e07db286fa258cb6aa55c Mon Sep 17 00:00:00 2001 From: nico Date: Fri, 12 Apr 2024 12:57:30 +0800 Subject: [PATCH] fix: known bugs. --- database/texas.go | 23 +++++++++++++++++++++++ go.mod | 2 +- go.sum | 2 ++ state/game/texas/bet.go | 5 ++--- state/game/texas/init.go | 7 +++---- state/game/texas/round.go | 2 +- 6 files changed, 32 insertions(+), 9 deletions(-) diff --git a/database/texas.go b/database/texas.go index 1c8a6be..8356299 100644 --- a/database/texas.go +++ b/database/texas.go @@ -72,6 +72,29 @@ func (g *Texas) Bet(player *TexasPlayer, amount uint) { } } +func (g *Texas) RoundEnd(currentPlayerId int64) bool { + if g.AllIn == len(g.Players) || + g.AllIn+g.Folded == len(g.Players) || + (g.MaxBetPlayer != nil && g.MaxBetPlayer.ID == currentPlayerId) { + return true + } + // all players except one folded or allin + if g.AllIn+g.Folded == len(g.Players)-1 { + isEnd := true + for _, p := range g.Players { + if p.Folded { + continue + } + if p.Bets != g.MaxBetAmount { + isEnd = false + break + } + } + return isEnd + } + return false +} + type TexasPlayer struct { ID int64 `json:"id"` Name string `json:"name"` diff --git a/go.mod b/go.mod index 6913c1b..abe79c7 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/feel-easy/mahjong v0.0.0-20220721030133-7a0f4032c008 github.com/feel-easy/uno v0.0.0-20220721061415-e6a3189cfd70 github.com/gorilla/websocket v1.4.2 - github.com/ratel-online/core v0.0.0-20240411101817-d5cb908bcf49 + github.com/ratel-online/core v0.0.0-20240412044054-42ffde55324d ) require ( diff --git a/go.sum b/go.sum index c9d4fb2..dc4d19f 100644 --- a/go.sum +++ b/go.sum @@ -51,6 +51,8 @@ github.com/ratel-online/core v0.0.0-20240411045052-840504c4e7fc h1:usJbCKX8e1eLy github.com/ratel-online/core v0.0.0-20240411045052-840504c4e7fc/go.mod h1:8SYaPGDk9dVGnUIEkanZvV1ErTqd8OdedKNCwyXgRjI= github.com/ratel-online/core v0.0.0-20240411101817-d5cb908bcf49 h1:yESHztiCxllI22QToTpUcQS/MPzeQmxVIpzZdv+fHZM= github.com/ratel-online/core v0.0.0-20240411101817-d5cb908bcf49/go.mod h1:8SYaPGDk9dVGnUIEkanZvV1ErTqd8OdedKNCwyXgRjI= +github.com/ratel-online/core v0.0.0-20240412044054-42ffde55324d h1:F8Qcc9aUnNv5716ITYXlYKxuoWYDMTXAbBVwjDUmrsI= +github.com/ratel-online/core v0.0.0-20240412044054-42ffde55324d/go.mod h1:8SYaPGDk9dVGnUIEkanZvV1ErTqd8OdedKNCwyXgRjI= github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc= github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0= github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo= diff --git a/state/game/texas/bet.go b/state/game/texas/bet.go index 17fadfe..f5ab90d 100644 --- a/state/game/texas/bet.go +++ b/state/game/texas/bet.go @@ -12,9 +12,8 @@ import ( func bet(player *database.Player, game *database.Texas) error { texasPlayer := game.Player(player.ID) - if game.AllIn == len(game.Players) || - game.AllIn+game.Folded == len(game.Players) || - (game.MaxBetPlayer != nil && game.MaxBetPlayer.ID == player.ID) { + + if game.RoundEnd(player.ID) { return nextRound(game) } if texasPlayer.Folded || texasPlayer.AllIn { diff --git a/state/game/texas/init.go b/state/game/texas/init.go index e302c83..8132a14 100644 --- a/state/game/texas/init.go +++ b/state/game/texas/init.go @@ -19,7 +19,6 @@ func createGame(room *database.Room) (database.RoomGame, error) { index := 0 roomPlayers := database.RoomPlayers(room.ID) players := make([]*database.TexasPlayer, 0) - bigBlind, smallBlind := 0, 1 for playerId := range roomPlayers { player := database.GetPlayer(playerId) players = append(players, &database.TexasPlayer{ @@ -34,8 +33,8 @@ func createGame(room *database.Room) (database.RoomGame, error) { Room: room, Players: players, Pot: 0, - BB: bigBlind, - SB: smallBlind, + BB: 0, + SB: 1, Pool: base[len(players)*2:], MaxBetAmount: 20, Round: "start", @@ -77,7 +76,7 @@ func resetGame(room *database.Room) (database.RoomGame, error) { Players: players, Pot: 0, BB: (game.BB + 1) % len(players), - SB: (game.SB + 1) % len(players), + SB: (game.BB + 2) % len(players), Pool: base[len(players)*2:], MaxBetAmount: 20, Round: "start", diff --git a/state/game/texas/round.go b/state/game/texas/round.go index 8f3e503..b69289e 100644 --- a/state/game/texas/round.go +++ b/state/game/texas/round.go @@ -159,7 +159,7 @@ func settlementRound(game *database.Texas) error { winner.Add(game.Pot / uint(len(winners))) } } - buf.WriteString("Please room creator to start a new game\n") + buf.WriteString(fmt.Sprintf("Please room owner %s to start a new game\n", database.GetPlayer(game.Room.Creator).Name)) database.Broadcast(game.Room.ID, buf.String()) room := game.Room