From a87e4934252b8d9fc3745a7e67638746f8b2e79e Mon Sep 17 00:00:00 2001 From: Trevor Slocum Date: Mon, 27 Nov 2023 17:48:43 -0800 Subject: [PATCH] Add MayChooseRoll --- cmd/bgammon-server/game.go | 8 +++++++- gamestate.go | 6 ++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/cmd/bgammon-server/game.go b/cmd/bgammon-server/game.go index 0d24bff..0fa2cd2 100644 --- a/cmd/bgammon-server/game.go +++ b/cmd/bgammon-server/game.go @@ -350,12 +350,18 @@ func (g *serverGame) listing(playerName []byte) *bgammon.GameListing { } else { playerCount = g.playerCount() } + + name := string(g.name) + if g.Acey { + name = "(Acey-deucey) " + name + } + return &bgammon.GameListing{ ID: g.id, Points: g.Points, Password: len(g.password) != 0, Players: playerCount, - Name: string(g.name), + Name: name, } } diff --git a/gamestate.go b/gamestate.go index 80a7f3f..acee35d 100644 --- a/gamestate.go +++ b/gamestate.go @@ -105,6 +105,12 @@ func (g *GameState) MayRoll() bool { } } +// MayChooseRoll returns whether the player may send the 'ok' command, supplying +// the chosen roll. This command only applies to acey-deucey games. +func (g *GameState) MayChooseRoll() bool { + return g.Acey && g.Turn != 0 && g.Turn == g.PlayerNumber && ((g.Roll1 == 1 && g.Roll2 == 2) || (g.Roll1 == 2 && g.Roll2 == 1)) +} + // MayOK returns whether the player may send the 'ok' command. func (g *GameState) MayOK() bool { if g.Spectating || g.Winner != 0 {