reorder built-in ruleset stages so game over is checked first (#79)

This commit is contained in:
Rob O'Dwyer 2022-06-01 15:21:27 -07:00 committed by GitHub
parent f0dc0bcb38
commit 426da8ac5e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 17 additions and 43 deletions

View file

@ -1,12 +1,12 @@
package rules
var soloRulesetStages = []string{
StageGameOverSoloSnake,
StageMovementStandard,
StageStarvationStandard,
StageHazardDamageStandard,
StageFeedSnakesStandard,
StageEliminationStandard,
StageGameOverSoloSnake,
}
type SoloRuleset struct {
@ -19,6 +19,11 @@ func (r SoloRuleset) Execute(bs *BoardState, s Settings, sm []SnakeMove) (bool,
return NewPipeline(soloRulesetStages...).Execute(bs, s, sm)
}
func (r *SoloRuleset) CreateNextBoardState(prevState *BoardState, moves []SnakeMove) (*BoardState, error) {
_, nextState, err := r.Execute(prevState, r.Settings(), moves)
return nextState, err
}
func (r *SoloRuleset) IsGameOver(b *BoardState) (bool, error) {
return GameOverSolo(b, r.Settings(), nil)
}