-
Notifications
You must be signed in to change notification settings - Fork 52
/
constrictor_test.go
76 lines (73 loc) · 1.78 KB
/
constrictor_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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)
// also test a pipeline with the same settings
gc.requireValidNextState(t, NewRulesetBuilder().PipelineRuleset(GameTypeConstrictor, NewPipeline(constrictorRulesetStages...)))
}
}