DEV-1761: New rules API (#118)
* DEV-1761: Clean up Ruleset interface (#115) * remove legacy ruleset types and simplify ruleset interface * remove unnecessary settings argument from Ruleset interface * decouple rules.Settings from client API and store settings as strings * DEV 1761: Add new BoardState and Point fields (#117) * add Point.TTL, Point.Value, GameState and PointState to BoardState * allow maps to access BoardState.GameState,PointState * add PreUpdateBoard and refactor snail_mode with it * fix bug where an extra turn was printed to the console * fix formatting * fix lint errors Co-authored-by: JonathanArns <jonathan.arns@googlemail.com>
This commit is contained in:
parent
639362ef46
commit
82e1999126
50 changed files with 1349 additions and 1610 deletions
|
|
@ -4,10 +4,6 @@ import (
|
|||
"testing"
|
||||
)
|
||||
|
||||
func TestConstrictorRulesetInterface(t *testing.T) {
|
||||
var _ Ruleset = (*ConstrictorRuleset)(nil)
|
||||
}
|
||||
|
||||
// Test that two equal snakes collide and both get eliminated
|
||||
// also checks:
|
||||
// - food removed
|
||||
|
|
@ -21,16 +17,16 @@ var constrictorMoveAndCollideMAD = gameTestCase{
|
|||
Snakes: []Snake{
|
||||
{
|
||||
ID: "one",
|
||||
Body: []Point{{1, 1}, {2, 1}},
|
||||
Body: []Point{{X: 1, Y: 1}, {X: 2, Y: 1}},
|
||||
Health: 99,
|
||||
},
|
||||
{
|
||||
ID: "two",
|
||||
Body: []Point{{1, 2}, {2, 2}},
|
||||
Body: []Point{{X: 1, Y: 2}, {X: 2, Y: 2}},
|
||||
Health: 99,
|
||||
},
|
||||
},
|
||||
Food: []Point{{10, 10}, {9, 9}, {8, 8}},
|
||||
Food: []Point{{X: 10, Y: 10}, {X: 9, Y: 9}, {X: 8, Y: 8}},
|
||||
Hazards: []Point{},
|
||||
},
|
||||
[]SnakeMove{
|
||||
|
|
@ -44,7 +40,7 @@ var constrictorMoveAndCollideMAD = gameTestCase{
|
|||
Snakes: []Snake{
|
||||
{
|
||||
ID: "one",
|
||||
Body: []Point{{1, 2}, {1, 1}, {1, 1}},
|
||||
Body: []Point{{X: 1, Y: 2}, {X: 1, Y: 1}, {X: 1, Y: 1}},
|
||||
Health: 100,
|
||||
EliminatedCause: EliminatedByCollision,
|
||||
EliminatedBy: "two",
|
||||
|
|
@ -52,7 +48,7 @@ var constrictorMoveAndCollideMAD = gameTestCase{
|
|||
},
|
||||
{
|
||||
ID: "two",
|
||||
Body: []Point{{1, 1}, {1, 2}, {1, 2}},
|
||||
Body: []Point{{X: 1, Y: 1}, {X: 1, Y: 2}, {X: 1, Y: 2}},
|
||||
Health: 100,
|
||||
EliminatedCause: EliminatedByCollision,
|
||||
EliminatedBy: "one",
|
||||
|
|
@ -70,15 +66,11 @@ func TestConstrictorCreateNextBoardState(t *testing.T) {
|
|||
standardCaseErrZeroLengthSnake,
|
||||
constrictorMoveAndCollideMAD,
|
||||
}
|
||||
rb := NewRulesetBuilder().WithParams(map[string]string{
|
||||
ParamGameType: GameTypeConstrictor,
|
||||
})
|
||||
r := ConstrictorRuleset{}
|
||||
r := NewRulesetBuilder().NamedRuleset(GameTypeConstrictor)
|
||||
for _, gc := range cases {
|
||||
gc.requireValidNextState(t, &r)
|
||||
// also test a RulesBuilder constructed instance
|
||||
gc.requireValidNextState(t, rb.Ruleset())
|
||||
// test a RulesBuilder constructed instance
|
||||
gc.requireValidNextState(t, r)
|
||||
// also test a pipeline with the same settings
|
||||
gc.requireValidNextState(t, rb.PipelineRuleset(GameTypeConstrictor, NewPipeline(constrictorRulesetStages...)))
|
||||
gc.requireValidNextState(t, NewRulesetBuilder().PipelineRuleset(GameTypeConstrictor, NewPipeline(constrictorRulesetStages...)))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue