Skip to content

Commit

Permalink
Fix bug with awarding envido points. Small improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
marianogappa committed Jul 23, 2024
1 parent 4cf8615 commit 23af3b3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 17 deletions.
13 changes: 0 additions & 13 deletions truco/actions_any_truco.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,6 @@ func (g GameState) AnyTrucoActionIsPossible(a Action) bool {
return g.TrucoSequence.CanAddStep(a.GetName())
}

func (g GameState) IsLastActionOfName(name string) bool {
actionsLog := g.RoundsLog[g.RoundNumber].ActionsLog
if len(actionsLog) == 0 {
return false
}
lastActionBs := actionsLog[len(actionsLog)-1].Action
lastAction, err := DeserializeAction(lastActionBs)
if err != nil {
return false
}
return lastAction.GetName() == name
}

func (g *GameState) AnyTrucoActionRunAction(at Action) error {
if !g.AnyTrucoActionIsPossible(at) {
return errActionNotPossible
Expand Down
12 changes: 8 additions & 4 deletions truco/truco.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ type GameState struct {
// a player reaches 30 points.
IsGameEnded bool `json:"isGameEnded"`

// WinnerPlayerID is the player ID of the player who won the game. This is only set when `IsEnded` is
// WinnerPlayerID is the player ID of the player who won the game. This is only set when `IsGameEnded` is
// `true`. Otherwise, it's -1.
WinnerPlayerID int `json:"winnerPlayerID"`

Expand Down Expand Up @@ -187,7 +187,7 @@ func (g *GameState) RunAction(action Action) error {
}

if g.IsGameEnded {
return errGameIsEnded
return fmt.Errorf("%w trying to run [%v]", errGameIsEnded, action)
}

if !g.IsRoundFinished && action.GetPlayerID() != g.TurnPlayerID {
Expand Down Expand Up @@ -271,6 +271,9 @@ func (g *GameState) canAwardEnvidoPoints(revealedHand Hand) bool {
if wonBy == -1 {
return false
}
if !g.EnvidoSequence.WasAccepted() {
return false
}
if g.EnvidoSequence.EnvidoPointsAwarded {
return false
}
Expand Down Expand Up @@ -426,7 +429,8 @@ func _serializeActions(as []Action) []json.RawMessage {
}

func _deserializeCurrentRoundLastAction(g GameState) Action {
a, _ := DeserializeAction(g.RoundsLog[g.RoundNumber].ActionsLog[len(g.RoundsLog[g.RoundNumber].ActionsLog)-1].Action)
lastAction := g.RoundsLog[g.RoundNumber].ActionsLog[len(g.RoundsLog[g.RoundNumber].ActionsLog)-1].Action
a, _ := DeserializeAction(lastAction)
return a
}

Expand Down Expand Up @@ -527,7 +531,7 @@ type ClientGameState struct {

IsRoundFinished bool `json:"isRoundFinished"`

// WinnerPlayerID is the player ID of the player who won the game. This is only set when `IsEnded` is
// WinnerPlayerID is the player ID of the player who won the game. This is only set when `IsGameEnded` is
// `true`. Otherwise, it's -1.
WinnerPlayerID int `json:"winnerPlayerID"`

Expand Down

0 comments on commit 23af3b3

Please sign in to comment.