Rename "EliminatedByStarvation" > "EliminatedByOutOfHealth"
This commit is contained in:
parent
92592c2aba
commit
f5aec61e04
5 changed files with 27 additions and 25 deletions
|
|
@ -108,9 +108,11 @@ func (r *RoyaleRuleset) damageOutOfBounds(b *BoardState) error {
|
||||||
if head == p {
|
if head == p {
|
||||||
// Snake is now out of bounds, reduce health
|
// Snake is now out of bounds, reduce health
|
||||||
snake.Health = snake.Health - r.DamagePerTurn
|
snake.Health = snake.Health - r.DamagePerTurn
|
||||||
if snake.Health <= 0 {
|
if snake.Health < 0 {
|
||||||
snake.Health = 0
|
snake.Health = 0
|
||||||
snake.EliminatedCause = EliminatedByStarvation
|
}
|
||||||
|
if r.StandardRuleset.snakeIsOutOfHealth(snake) {
|
||||||
|
snake.EliminatedCause = EliminatedByOutOfHealth
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -123,7 +123,7 @@ func TestRoyaleDamageOutOfBounds(t *testing.T) {
|
||||||
{
|
{
|
||||||
Snakes: []Snake{{Body: []Point{{0, 0}}}},
|
Snakes: []Snake{{Body: []Point{{0, 0}}}},
|
||||||
OutOfBounds: []Point{{0, 0}},
|
OutOfBounds: []Point{{0, 0}},
|
||||||
ExpectedEliminatedCauses: []string{EliminatedByStarvation},
|
ExpectedEliminatedCauses: []string{EliminatedByOutOfHealth},
|
||||||
ExpectedEliminatedByIDs: []string{""},
|
ExpectedEliminatedByIDs: []string{""},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -147,7 +147,7 @@ func TestRoyaleDamageOutOfBounds(t *testing.T) {
|
||||||
{Body: []Point{{3, 3}, {3, 4}, {3, 5}, {3, 6}}},
|
{Body: []Point{{3, 3}, {3, 4}, {3, 5}, {3, 6}}},
|
||||||
},
|
},
|
||||||
OutOfBounds: []Point{{3, 3}},
|
OutOfBounds: []Point{{3, 3}},
|
||||||
ExpectedEliminatedCauses: []string{NotEliminated, EliminatedByStarvation},
|
ExpectedEliminatedCauses: []string{NotEliminated, EliminatedByOutOfHealth},
|
||||||
ExpectedEliminatedByIDs: []string{"", ""},
|
ExpectedEliminatedByIDs: []string{"", ""},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
@ -177,14 +177,14 @@ func TestRoyaleDamagePerTurn(t *testing.T) {
|
||||||
{100, -100, 100, NotEliminated, errors.New("royale damage per turn must be greater than zero")},
|
{100, -100, 100, NotEliminated, errors.New("royale damage per turn must be greater than zero")},
|
||||||
{100, 1, 99, NotEliminated, nil},
|
{100, 1, 99, NotEliminated, nil},
|
||||||
{100, 99, 1, NotEliminated, nil},
|
{100, 99, 1, NotEliminated, nil},
|
||||||
{100, 100, 0, EliminatedByStarvation, nil},
|
{100, 100, 0, EliminatedByOutOfHealth, nil},
|
||||||
{100, 101, 0, EliminatedByStarvation, nil},
|
{100, 101, 0, EliminatedByOutOfHealth, nil},
|
||||||
{100, 999, 0, EliminatedByStarvation, nil},
|
{100, 999, 0, EliminatedByOutOfHealth, nil},
|
||||||
{2, 1, 1, NotEliminated, nil},
|
{2, 1, 1, NotEliminated, nil},
|
||||||
{1, 1, 0, EliminatedByStarvation, nil},
|
{1, 1, 0, EliminatedByOutOfHealth, nil},
|
||||||
{1, 999, 0, EliminatedByStarvation, nil},
|
{1, 999, 0, EliminatedByOutOfHealth, nil},
|
||||||
{0, 1, 0, EliminatedByStarvation, nil},
|
{0, 1, 0, EliminatedByOutOfHealth, nil},
|
||||||
{0, 999, 0, EliminatedByStarvation, nil},
|
{0, 999, 0, EliminatedByOutOfHealth, nil},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
|
@ -232,7 +232,7 @@ func TestRoyalDamageNextTurn(t *testing.T) {
|
||||||
b.Snakes[0].Health = 15
|
b.Snakes[0].Health = 15
|
||||||
n, err = r.CreateNextBoardState(b, m)
|
n, err = r.CreateNextBoardState(b, m)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, EliminatedByStarvation, n.Snakes[0].EliminatedCause)
|
require.Equal(t, EliminatedByOutOfHealth, n.Snakes[0].EliminatedCause)
|
||||||
require.Equal(t, int32(0), n.Snakes[0].Health)
|
require.Equal(t, int32(0), n.Snakes[0].Health)
|
||||||
require.Equal(t, Point{9, 0}, n.Snakes[0].Body[0])
|
require.Equal(t, Point{9, 0}, n.Snakes[0].Body[0])
|
||||||
require.Equal(t, 20, len(r.OutOfBounds))
|
require.Equal(t, 20, len(r.OutOfBounds))
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ func TestSquadAllowBodyCollisions(t *testing.T) {
|
||||||
{"R4", "red", EliminatedByCollision, "R4", EliminatedByCollision, "R4"}, // this is an error case but worth testing
|
{"R4", "red", EliminatedByCollision, "R4", EliminatedByCollision, "R4"}, // this is an error case but worth testing
|
||||||
{"R5", "red", EliminatedByCollision, "R4", NotEliminated, ""},
|
{"R5", "red", EliminatedByCollision, "R4", NotEliminated, ""},
|
||||||
// Green Squad
|
// Green Squad
|
||||||
{"G1", "green", EliminatedByStarvation, "x", EliminatedByStarvation, "x"},
|
{"G1", "green", EliminatedByOutOfHealth, "x", EliminatedByOutOfHealth, "x"},
|
||||||
// Yellow Squad
|
// Yellow Squad
|
||||||
{"Y1", "yellow", EliminatedByCollision, "B4", EliminatedByCollision, "B4"},
|
{"Y1", "yellow", EliminatedByCollision, "B4", EliminatedByCollision, "B4"},
|
||||||
}
|
}
|
||||||
|
|
@ -231,7 +231,7 @@ func TestSquadSharedElimination(t *testing.T) {
|
||||||
{"R3", "red", NotEliminated, "", EliminatedBySquad, ""},
|
{"R3", "red", NotEliminated, "", EliminatedBySquad, ""},
|
||||||
{"R4", "red", EliminatedByCollision, "B1", EliminatedByCollision, "B1"},
|
{"R4", "red", EliminatedByCollision, "B1", EliminatedByCollision, "B1"},
|
||||||
// Green Squad
|
// Green Squad
|
||||||
{"G1", "green", EliminatedByStarvation, "x", EliminatedByStarvation, "x"},
|
{"G1", "green", EliminatedByOutOfHealth, "x", EliminatedByOutOfHealth, "x"},
|
||||||
// Yellow Squad
|
// Yellow Squad
|
||||||
{"Y1", "yellow", NotEliminated, "", NotEliminated, ""},
|
{"Y1", "yellow", NotEliminated, "", NotEliminated, ""},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ const (
|
||||||
NotEliminated = ""
|
NotEliminated = ""
|
||||||
EliminatedByCollision = "snake-collision"
|
EliminatedByCollision = "snake-collision"
|
||||||
EliminatedBySelfCollision = "snake-self-collision"
|
EliminatedBySelfCollision = "snake-self-collision"
|
||||||
EliminatedByStarvation = "starvation"
|
EliminatedByOutOfHealth = "out-of-health"
|
||||||
EliminatedByHeadToHeadCollision = "head-collision"
|
EliminatedByHeadToHeadCollision = "head-collision"
|
||||||
EliminatedByOutOfBounds = "wall-collision"
|
EliminatedByOutOfBounds = "wall-collision"
|
||||||
|
|
||||||
|
|
@ -348,8 +348,8 @@ func (r *StandardRuleset) maybeEliminateSnakes(b *BoardState) error {
|
||||||
return errors.New("snake is length zero")
|
return errors.New("snake is length zero")
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.snakeHasStarved(snake) {
|
if r.snakeIsOutOfHealth(snake) {
|
||||||
snake.EliminatedCause = EliminatedByStarvation
|
snake.EliminatedCause = EliminatedByOutOfHealth
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -444,7 +444,7 @@ func (r *StandardRuleset) maybeEliminateSnakes(b *BoardState) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *StandardRuleset) snakeHasStarved(s *Snake) bool {
|
func (r *StandardRuleset) snakeIsOutOfHealth(s *Snake) bool {
|
||||||
return s.Health <= 0
|
return s.Health <= 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -627,7 +627,7 @@ func TestEatingOnLastMove(t *testing.T) {
|
||||||
ID: "two",
|
ID: "two",
|
||||||
Body: []Point{{3, 1}, {3, 2}, {3, 3}},
|
Body: []Point{{3, 1}, {3, 2}, {3, 3}},
|
||||||
Health: 0,
|
Health: 0,
|
||||||
EliminatedCause: EliminatedByStarvation,
|
EliminatedCause: EliminatedByOutOfHealth,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Food: []Point{{9, 9}},
|
Food: []Point{{9, 9}},
|
||||||
|
|
@ -783,7 +783,7 @@ func TestRegressionIssue19(t *testing.T) {
|
||||||
ID: "eliminated",
|
ID: "eliminated",
|
||||||
Body: []Point{{0, 0}, {0, 1}, {0, 2}, {0, 3}, {0, 4}, {0, 5}, {0, 6}},
|
Body: []Point{{0, 0}, {0, 1}, {0, 2}, {0, 3}, {0, 4}, {0, 5}, {0, 6}},
|
||||||
Health: 0,
|
Health: 0,
|
||||||
EliminatedCause: EliminatedByStarvation,
|
EliminatedCause: EliminatedByOutOfHealth,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Food: []Point{{9, 9}},
|
Food: []Point{{9, 9}},
|
||||||
|
|
@ -811,7 +811,7 @@ func TestRegressionIssue19(t *testing.T) {
|
||||||
ID: "eliminated",
|
ID: "eliminated",
|
||||||
Body: []Point{{0, 0}, {0, 1}, {0, 2}, {0, 3}, {0, 4}, {0, 5}, {0, 6}},
|
Body: []Point{{0, 0}, {0, 1}, {0, 2}, {0, 3}, {0, 4}, {0, 5}, {0, 6}},
|
||||||
Health: 0,
|
Health: 0,
|
||||||
EliminatedCause: EliminatedByStarvation,
|
EliminatedCause: EliminatedByOutOfHealth,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Food: []Point{{9, 9}},
|
Food: []Point{{9, 9}},
|
||||||
|
|
@ -1121,7 +1121,7 @@ func TestReduceSnakeHealth(t *testing.T) {
|
||||||
require.Equal(t, b.Snakes[2].Health, int32(50))
|
require.Equal(t, b.Snakes[2].Health, int32(50))
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSnakeHasStarved(t *testing.T) {
|
func TestSnakeIsOutOfHealth(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
Health int32
|
Health int32
|
||||||
Expected bool
|
Expected bool
|
||||||
|
|
@ -1140,7 +1140,7 @@ func TestSnakeHasStarved(t *testing.T) {
|
||||||
r := StandardRuleset{}
|
r := StandardRuleset{}
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
s := &Snake{Health: test.Health}
|
s := &Snake{Health: test.Health}
|
||||||
require.Equal(t, test.Expected, r.snakeHasStarved(s), "Health: %+v", test.Health)
|
require.Equal(t, test.Expected, r.snakeIsOutOfHealth(s), "Health: %+v", test.Health)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1372,7 +1372,7 @@ func TestMaybeEliminateSnakes(t *testing.T) {
|
||||||
[]Snake{
|
[]Snake{
|
||||||
Snake{ID: "1", Body: []Point{{1, 1}}},
|
Snake{ID: "1", Body: []Point{{1, 1}}},
|
||||||
},
|
},
|
||||||
[]string{EliminatedByStarvation},
|
[]string{EliminatedByOutOfHealth},
|
||||||
[]string{""},
|
[]string{""},
|
||||||
nil,
|
nil,
|
||||||
},
|
},
|
||||||
|
|
@ -1546,7 +1546,7 @@ func TestMaybeEliminateSnakesPriority(t *testing.T) {
|
||||||
{ID: "6", Health: 1, Body: []Point{{2, 2}, {2, 3}, {2, 4}, {2, 5}}},
|
{ID: "6", Health: 1, Body: []Point{{2, 2}, {2, 3}, {2, 4}, {2, 5}}},
|
||||||
},
|
},
|
||||||
[]string{
|
[]string{
|
||||||
EliminatedByStarvation,
|
EliminatedByOutOfHealth,
|
||||||
EliminatedByOutOfBounds,
|
EliminatedByOutOfBounds,
|
||||||
EliminatedBySelfCollision,
|
EliminatedBySelfCollision,
|
||||||
EliminatedByCollision,
|
EliminatedByCollision,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue