Skip to content

Commit

Permalink
new cause of death by hazard (#104)
Browse files Browse the repository at this point in the history
  • Loading branch information
robbles authored Aug 18, 2022
1 parent b1ddd2f commit 7d769b0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
1 change: 1 addition & 0 deletions constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const (
EliminatedByOutOfHealth = "out-of-health"
EliminatedByHeadToHeadCollision = "head-collision"
EliminatedByOutOfBounds = "wall-collision"
EliminatedByHazard = "hazard"

// Error constants
ErrorTooManySnakes = RulesetError("too many snakes for fixed start positions")
Expand Down
2 changes: 1 addition & 1 deletion standard.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func DamageHazardsStandard(b *BoardState, settings Settings, moves []SnakeMove)
snake.Health = SnakeMaxHealth
}
if snakeIsOutOfHealth(snake) {
EliminateSnake(snake, EliminatedByOutOfHealth, "", b.Turn+1)
EliminateSnake(snake, EliminatedByHazard, "", b.Turn+1)
}
}
}
Expand Down
18 changes: 9 additions & 9 deletions standard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1299,7 +1299,7 @@ func TestMaybeDamageHazards(t *testing.T) {
{
Snakes: []Snake{{Body: []Point{{0, 0}}}},
Hazards: []Point{{0, 0}},
ExpectedEliminatedCauses: []string{EliminatedByOutOfHealth},
ExpectedEliminatedCauses: []string{EliminatedByHazard},
ExpectedEliminatedByIDs: []string{""},
ExpectedEliminatedOnTurns: []int{42},
},
Expand Down Expand Up @@ -1334,7 +1334,7 @@ func TestMaybeDamageHazards(t *testing.T) {
{Body: []Point{{3, 3}, {3, 4}, {3, 5}, {3, 6}}},
},
Hazards: []Point{{3, 3}},
ExpectedEliminatedCauses: []string{NotEliminated, EliminatedByOutOfHealth},
ExpectedEliminatedCauses: []string{NotEliminated, EliminatedByHazard},
ExpectedEliminatedByIDs: []string{"", ""},
ExpectedEliminatedOnTurns: []int{0, 42},
},
Expand Down Expand Up @@ -1370,15 +1370,15 @@ func TestHazardDamagePerTurn(t *testing.T) {
{100, 99, true, 100, NotEliminated, nil},
{100, -1, false, 100, NotEliminated, nil},
{99, -2, false, 100, NotEliminated, nil},
{100, 100, false, 0, EliminatedByOutOfHealth, nil},
{100, 101, false, 0, EliminatedByOutOfHealth, nil},
{100, 999, false, 0, EliminatedByOutOfHealth, nil},
{100, 100, false, 0, EliminatedByHazard, nil},
{100, 101, false, 0, EliminatedByHazard, nil},
{100, 999, false, 0, EliminatedByHazard, nil},
{100, 100, true, 100, NotEliminated, nil},
{2, 1, false, 1, NotEliminated, nil},
{1, 1, false, 0, EliminatedByOutOfHealth, nil},
{1, 999, false, 0, EliminatedByOutOfHealth, nil},
{0, 1, false, 0, EliminatedByOutOfHealth, nil},
{0, 999, false, 0, EliminatedByOutOfHealth, nil},
{1, 1, false, 0, EliminatedByHazard, nil},
{1, 999, false, 0, EliminatedByHazard, nil},
{0, 1, false, 0, EliminatedByHazard, nil},
{0, 999, false, 0, EliminatedByHazard, nil},
}

for _, test := range tests {
Expand Down

0 comments on commit 7d769b0

Please sign in to comment.