new cause of death by hazard (#104)

This commit is contained in:
Rob O'Dwyer 2022-08-18 16:20:50 -07:00 committed by GitHub
parent b1ddd2f4ca
commit 7d769b01b6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 10 deletions

View file

@ -26,6 +26,7 @@ const (
EliminatedByOutOfHealth = "out-of-health" EliminatedByOutOfHealth = "out-of-health"
EliminatedByHeadToHeadCollision = "head-collision" EliminatedByHeadToHeadCollision = "head-collision"
EliminatedByOutOfBounds = "wall-collision" EliminatedByOutOfBounds = "wall-collision"
EliminatedByHazard = "hazard"
// Error constants // Error constants
ErrorTooManySnakes = RulesetError("too many snakes for fixed start positions") ErrorTooManySnakes = RulesetError("too many snakes for fixed start positions")

View file

@ -184,7 +184,7 @@ func DamageHazardsStandard(b *BoardState, settings Settings, moves []SnakeMove)
snake.Health = SnakeMaxHealth snake.Health = SnakeMaxHealth
} }
if snakeIsOutOfHealth(snake) { if snakeIsOutOfHealth(snake) {
EliminateSnake(snake, EliminatedByOutOfHealth, "", b.Turn+1) EliminateSnake(snake, EliminatedByHazard, "", b.Turn+1)
} }
} }
} }

View file

@ -1299,7 +1299,7 @@ func TestMaybeDamageHazards(t *testing.T) {
{ {
Snakes: []Snake{{Body: []Point{{0, 0}}}}, Snakes: []Snake{{Body: []Point{{0, 0}}}},
Hazards: []Point{{0, 0}}, Hazards: []Point{{0, 0}},
ExpectedEliminatedCauses: []string{EliminatedByOutOfHealth}, ExpectedEliminatedCauses: []string{EliminatedByHazard},
ExpectedEliminatedByIDs: []string{""}, ExpectedEliminatedByIDs: []string{""},
ExpectedEliminatedOnTurns: []int{42}, ExpectedEliminatedOnTurns: []int{42},
}, },
@ -1334,7 +1334,7 @@ func TestMaybeDamageHazards(t *testing.T) {
{Body: []Point{{3, 3}, {3, 4}, {3, 5}, {3, 6}}}, {Body: []Point{{3, 3}, {3, 4}, {3, 5}, {3, 6}}},
}, },
Hazards: []Point{{3, 3}}, Hazards: []Point{{3, 3}},
ExpectedEliminatedCauses: []string{NotEliminated, EliminatedByOutOfHealth}, ExpectedEliminatedCauses: []string{NotEliminated, EliminatedByHazard},
ExpectedEliminatedByIDs: []string{"", ""}, ExpectedEliminatedByIDs: []string{"", ""},
ExpectedEliminatedOnTurns: []int{0, 42}, ExpectedEliminatedOnTurns: []int{0, 42},
}, },
@ -1370,15 +1370,15 @@ func TestHazardDamagePerTurn(t *testing.T) {
{100, 99, true, 100, NotEliminated, nil}, {100, 99, true, 100, NotEliminated, nil},
{100, -1, false, 100, NotEliminated, nil}, {100, -1, false, 100, NotEliminated, nil},
{99, -2, false, 100, NotEliminated, nil}, {99, -2, false, 100, NotEliminated, nil},
{100, 100, false, 0, EliminatedByOutOfHealth, nil}, {100, 100, false, 0, EliminatedByHazard, nil},
{100, 101, false, 0, EliminatedByOutOfHealth, nil}, {100, 101, false, 0, EliminatedByHazard, nil},
{100, 999, false, 0, EliminatedByOutOfHealth, nil}, {100, 999, false, 0, EliminatedByHazard, nil},
{100, 100, true, 100, NotEliminated, nil}, {100, 100, true, 100, NotEliminated, nil},
{2, 1, false, 1, NotEliminated, nil}, {2, 1, false, 1, NotEliminated, nil},
{1, 1, false, 0, EliminatedByOutOfHealth, nil}, {1, 1, false, 0, EliminatedByHazard, nil},
{1, 999, false, 0, EliminatedByOutOfHealth, nil}, {1, 999, false, 0, EliminatedByHazard, nil},
{0, 1, false, 0, EliminatedByOutOfHealth, nil}, {0, 1, false, 0, EliminatedByHazard, nil},
{0, 999, false, 0, EliminatedByOutOfHealth, nil}, {0, 999, false, 0, EliminatedByHazard, nil},
} }
for _, test := range tests { for _, test := range tests {