Implementing movement on a grid
- by Dvole
I have a simple snake game, where I have other NPC snakes on the field.
How do I calculate the movement of those other snakes so that they did not hit walls, and each other?
So far I have it like this:
I check for current coordinates and when there is a wall nearby I change direction to some other one. And so on, this way the snakes never collide the walls.
But not actually colliding other snakes, how do I prevent this?
I figured I could probe for the direction I'm heading and if there is anything there I would change direction too, but there is a set of situation where this won't work, for example if another snake will block off all exits later.