From 805658ee7ec1590e85bedf6c8b369a57811b5cd1 Mon Sep 17 00:00:00 2001 From: Mariano Gappa Date: Tue, 25 Jun 2024 20:44:02 +0100 Subject: [PATCH] Fix envido yields turn rules bug. --- truco/action_any_quiero.go | 5 +++++ truco/action_son_buenas.go | 2 +- truco/action_son_mejores.go | 2 +- truco/actions.go | 3 +++ truco/truco.go | 2 +- 5 files changed, 11 insertions(+), 3 deletions(-) diff --git a/truco/action_any_quiero.go b/truco/action_any_quiero.go index 1b1e655..f0ca87a 100644 --- a/truco/action_any_quiero.go +++ b/truco/action_any_quiero.go @@ -101,3 +101,8 @@ func (a ActionSayTrucoQuiero) YieldsTurn(g GameState) bool { // is not the one who started the sub-sequence. return g.TurnPlayerID != g.TrucoSequence.StartingPlayerID } + +func (a ActionSayEnvidoNoQuiero) YieldsTurn(g GameState) bool { + // In son_buenas/son_mejores/no_quiero, the turn should go to whoever started the sequence + return g.TurnPlayerID != g.EnvidoSequence.StartingPlayerID +} diff --git a/truco/action_son_buenas.go b/truco/action_son_buenas.go index df7d6e7..74cfa88 100644 --- a/truco/action_son_buenas.go +++ b/truco/action_son_buenas.go @@ -48,6 +48,6 @@ func (a ActionSaySonBuenas) Run(g *GameState) error { } func (a ActionSaySonBuenas) YieldsTurn(g GameState) bool { - // In son_buenas/son_mejores, the turn should go to whoever started the sequence + // In son_buenas/son_mejores/no_quiero, the turn should go to whoever started the sequence return g.TurnPlayerID != g.EnvidoSequence.StartingPlayerID } diff --git a/truco/action_son_mejores.go b/truco/action_son_mejores.go index afd04da..d55f6a6 100644 --- a/truco/action_son_mejores.go +++ b/truco/action_son_mejores.go @@ -47,6 +47,6 @@ func (a ActionSaySonMejores) Run(g *GameState) error { } func (a ActionSaySonMejores) YieldsTurn(g GameState) bool { - // In son_buenas/son_mejores, the turn should go to whoever started the sequence + // In son_buenas/son_mejores/no_quiero, the turn should go to whoever started the sequence return g.TurnPlayerID != g.EnvidoSequence.StartingPlayerID } diff --git a/truco/actions.go b/truco/actions.go index 09d3920..3980d61 100644 --- a/truco/actions.go +++ b/truco/actions.go @@ -9,6 +9,9 @@ func (a act) GetName() string { } func (a act) YieldsTurn(g GameState) bool { + // if a.Name == SAY_ENVIDO_NO_QUIERO { + // log.Printf("Player %d started the envido sequence, player %v just said no quiero, yields should return: %v but I'm returning true\n", g.EnvidoSequence.StartingPlayerID, g.TurnPlayerID, g.TurnPlayerID != g.EnvidoSequence.StartingPlayerID) + // } return true } diff --git a/truco/truco.go b/truco/truco.go index 39b2aeb..593030f 100644 --- a/truco/truco.go +++ b/truco/truco.go @@ -202,7 +202,6 @@ func (g *GameState) RunAction(action Action) error { if !g.IsEnded && !g.RoundFinished && action.YieldsTurn(*g) { g.TurnPlayerID = g.OpponentOf(g.TurnPlayerID) } - g.PossibleActions = g.CalculatePossibleActions() // Handle end of game due to score // TODO: this changes if players are not 0 & 1 (or more than 2 players) @@ -216,6 +215,7 @@ func (g *GameState) RunAction(action Action) error { } } + g.PossibleActions = g.CalculatePossibleActions() return nil }