Prioritize self-collisions over other collisions. Fixes #16.
This commit is contained in:
parent
c74436e709
commit
5aec70de2b
3 changed files with 103 additions and 7 deletions
20
standard.go
20
standard.go
|
|
@ -349,15 +349,21 @@ func (r *StandardRuleset) maybeEliminateSnakes(b *BoardState) error {
|
|||
continue
|
||||
}
|
||||
|
||||
// Always check body collisions before head-to-heads
|
||||
// Check for self-collisions first
|
||||
if r.snakeHasBodyCollided(snake, snake) {
|
||||
snake.EliminatedCause = EliminatedBySelfCollision
|
||||
snake.EliminatedBy = snake.ID
|
||||
continue
|
||||
}
|
||||
|
||||
// Check for body collisions with other snakes second
|
||||
for _, otherIndex := range snakeIndicesByLength {
|
||||
other := &b.Snakes[otherIndex]
|
||||
if snake.ID == other.ID {
|
||||
continue
|
||||
}
|
||||
if r.snakeHasBodyCollided(snake, other) {
|
||||
if snake.ID == other.ID {
|
||||
snake.EliminatedCause = EliminatedBySelfCollision
|
||||
} else {
|
||||
snake.EliminatedCause = EliminatedByCollision
|
||||
}
|
||||
snake.EliminatedCause = EliminatedByCollision
|
||||
snake.EliminatedBy = other.ID
|
||||
break
|
||||
}
|
||||
|
|
@ -366,7 +372,7 @@ func (r *StandardRuleset) maybeEliminateSnakes(b *BoardState) error {
|
|||
continue
|
||||
}
|
||||
|
||||
// Always check head-to-heads after body collisions
|
||||
// Check for head-to-heads last
|
||||
for _, otherIndex := range snakeIndicesByLength {
|
||||
other := &b.Snakes[otherIndex]
|
||||
if snake.ID != other.ID && r.snakeHasLostHeadToHead(snake, other) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue