Refactor rulesets into smaller composable operations In order to mix up the functionality from different rulesets like Solo, Royale, etc. the code in these classes needs to be broken up into small functions that can be composed in a pipeline to make a custom game mode.
20 lines
470 B
Go
20 lines
470 B
Go
package rules
|
|
|
|
type SoloRuleset struct {
|
|
StandardRuleset
|
|
}
|
|
|
|
func (r *SoloRuleset) Name() string { return GameTypeSolo }
|
|
|
|
func (r *SoloRuleset) IsGameOver(b *BoardState) (bool, error) {
|
|
return r.callStageFunc(GameOverSolo, b, []SnakeMove{})
|
|
}
|
|
|
|
func GameOverSolo(b *BoardState, settings Settings, moves []SnakeMove) (bool, error) {
|
|
for i := 0; i < len(b.Snakes); i++ {
|
|
if b.Snakes[i].EliminatedCause == NotEliminated {
|
|
return false, nil
|
|
}
|
|
}
|
|
return true, nil
|
|
}
|