Skip to content

Commit

Permalink
Fix envido yields turn rules bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
marianogappa committed Jun 25, 2024
1 parent 987cabc commit 805658e
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 3 deletions.
5 changes: 5 additions & 0 deletions truco/action_any_quiero.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion truco/action_son_buenas.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion truco/action_son_mejores.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
3 changes: 3 additions & 0 deletions truco/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion truco/truco.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -216,6 +215,7 @@ func (g *GameState) RunAction(action Action) error {
}
}

g.PossibleActions = g.CalculatePossibleActions()
return nil
}

Expand Down

0 comments on commit 805658e

Please sign in to comment.