Byte-snake-engine/constrictor_test.go

77 lines
1.8 KiB
Go
Raw Normal View History

package rules
import (
"testing"
)
// Test that two equal snakes collide and both get eliminated
// also checks:
// - food removed
// - health back to max
var constrictorMoveAndCollideMAD = gameTestCase{
"Constrictor Case Move and Collide",
&BoardState{
Turn: 41,
Width: 10,
Height: 10,
Snakes: []Snake{
{
ID: "one",
Body: []Point{{X: 1, Y: 1}, {X: 2, Y: 1}},
Health: 99,
},
{
ID: "two",
Body: []Point{{X: 1, Y: 2}, {X: 2, Y: 2}},
Health: 99,
},
},
Food: []Point{{X: 10, Y: 10}, {X: 9, Y: 9}, {X: 8, Y: 8}},
Hazards: []Point{},
},
[]SnakeMove{
{ID: "one", Move: MoveUp},
{ID: "two", Move: MoveDown},
},
nil,
&BoardState{
Width: 10,
Height: 10,
Snakes: []Snake{
{
ID: "one",
Body: []Point{{X: 1, Y: 2}, {X: 1, Y: 1}, {X: 1, Y: 1}},
Health: 100,
EliminatedCause: EliminatedByCollision,
EliminatedBy: "two",
EliminatedOnTurn: 42,
},
{
ID: "two",
Body: []Point{{X: 1, Y: 1}, {X: 1, Y: 2}, {X: 1, Y: 2}},
Health: 100,
EliminatedCause: EliminatedByCollision,
EliminatedBy: "one",
EliminatedOnTurn: 42,
},
},
Food: []Point{},
Hazards: []Point{},
},
}
func TestConstrictorCreateNextBoardState(t *testing.T) {
cases := []gameTestCase{
standardCaseErrNoMoveFound,
standardCaseErrZeroLengthSnake,
constrictorMoveAndCollideMAD,
}
r := NewRulesetBuilder().NamedRuleset(GameTypeConstrictor)
for _, gc := range cases {
// test a RulesBuilder constructed instance
gc.requireValidNextState(t, r)
DEV-1096 - add a new "pipeline" concept (#67) * add a new "pipeline" concept - added new Pipeline type which is a series of stages - added a global registry to facilitate plugin architecture - 100% test coverage * Refactor rulesets to provide and use Pipeline * fix copypasta comments * fix lint for unused method * include game over stages in ruleset pipelines * clean up unused private standard methods * remove unused private methods in squad ruleset * remove unused private methods in royale ruleset * refactor: pipeline clone + return next board state * YAGNI: remove unused Append * refactor: improve stage names * add no-op behavior to stages for initial state * refactor: no-op decision within stage functions * remove misleading comment that isn't true * dont bother checking for init in gameover stages * remove redundant test * refactor: provide a combined ruleset/pipeline type * fix: movement no-op for GameOver check IsGameOver needs to run pipeline, move snakes needs to no-op for that * add test coverage * refactor: improve stage names and use constants * add Error method Support error checking before calling Execute() * update naming to be American style * panic when overwriting stages in global registry * rename "Error" method and improve docs * use testify lib for panic assertion * remove redundant food stage * use ruleset-specific logic for game over checks * re-work Pipeline errors * rework errors again * add defensive check for zero length snake * use old logic which checks current state, not next * add warning about how PipelineRuleset checks for game over
2022-04-19 15:52:57 -07:00
// also test a pipeline with the same settings
gc.requireValidNextState(t, NewRulesetBuilder().PipelineRuleset(GameTypeConstrictor, NewPipeline(constrictorRulesetStages...)))
}
}