Skip to content

Commit

Permalink
fix: known bugs.
Browse files Browse the repository at this point in the history
  • Loading branch information
ainilili committed Apr 12, 2024
1 parent b8e3885 commit dc41b35
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 9 deletions.
23 changes: 23 additions & 0 deletions database/texas.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
5 changes: 2 additions & 3 deletions state/game/texas/bet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 3 additions & 4 deletions state/game/texas/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion state/game/texas/round.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit dc41b35

Please sign in to comment.