cygni / snakebot

http://snake.cygni.se
MIT License
2 stars 7 forks source link

Bug: Sometimes snakes might die with a valid move (CollisionWithSnake) #112

Open Dolvur opened 1 year ago

Dolvur commented 1 year ago

I have noticed that snakes sometimes die with a valid move. Below is an example of this with the training bot Snakey dying.

https://user-images.githubusercontent.com/69213759/232209462-b9244608-e42d-4c4e-8124-882a307a6bbe.mp4

I have gotten similar behavior with my own bot sometimes when running and was confused since the direction it printed to go was a valid direction. This time I noticed it happening with one of the training bots and I even logged all the directions received from the server:

snakey dies valid moves logs

The exception raised is CollisionWithSnake and not CollisionWithSelf. This only seems to be called at MoveSnake.java

// Snakes are allowed to follow their own tail as long as
// they don't grow or their tail comes after their head.
// Collision with an opponent's tail cannot happen here because
// this transformer expects only one snake in the world.
if (targetContent instanceof SnakePart ) &&
  (forceGrowth  ||
  !((SnakePart)targetContent).isTail() ||
  snakeHead.getLength() == 2)) {
    throw new SnakeCollision(targetSnakePos, snakeHead);
}

Unsure if this is the issue but this part looks correlated with the other bug #111

@emilb perhaps you have an idea?

I am gonna test a little bit more, but the bug is very inconsistent.