Winning a game of Battlesnake is deceptively simple; be the last Battlesnake left slithering on the game board. In order to accomplish this, your Battlesnake will need health and space - if it runs out of either, it will be eliminated.
At the start of every game, each Battlesnake will be placed on the game board alongside their opponents, each starting with a full health meter.
On every turn your Battlesnake will choose to move in a direction, one of up, down, left, or right. Moving in any direction will drain your Battlesnake of one health point, and your Battlesnake must move once per turn.
In order to restore the health your Battlesnake needs to survive, it must consume the traditional food of Battlesnakes: brightly colored nutritional discs.
These flavorful discs will appear throughout the game and remain on the game board until consumed. Battlesnakes that enter the same square as a piece of food will immediately consume it, filling their health to maximum. But ravenous consumption comes at a cost...
Every time a Battlesnake consumes food it will grow longer, making it more difficult for itself (and others!) to survive. Consuming food costs no health, meaning a Battlesnake can safely eat at one health point and be rejuventated in time to keep moving.
At the beginning of each game some amount of food will be placed around the board. On each subsequent turn additional food may be added (according to our Super Secret Proprietary Algorithm*). It's also possible for multiple pieces of food to appear on any single turn.
Battlesnakes need more than just food to survive, they need space to roam free and be their best possible selves. However, space on the game board is limited.
As the game progresses and all Battlesnakes consume food to stay healthy, finding the best path through the available spaces becomes increasingly challenging. Eventually all Battlesnakes will run out of room.
Your goal is to have your opponents run out of room before you do.
The game is played on a rectangular game board of variable size with up to eight Battlesnakes competing at the same time, each of variable length.
Most importantly the game board is surrounded by walls - any Battlesnake attempting to move outside the boundaries of these walls will be eliminated from the game.
There are three types of collisions that your Battlesnake should be aware of.
Self Collisions. If your Battlesnake collides with its own body, it will be immediately eliminated. This is the easiest type of collision to avoid, and is a good starting goal for new Battlesnake developers.
Body Collisions. Battlesnake is a game of wits and honor. If your Battlesnake attempts to consume another Battlesnake, it will be eliminated from the game for unsports-snake-like conduct.
Head-to-Head Collisions. The one exception to Body Collisions is when two Battlesnakes meet head-to-head. In this scenario, the outcome is a little more complex: the larger Battlesnake will survive and the shorter will be eliminated. If both are the same size, then both are eliminated.
At the beginning of each game every Battlesnake will be the same size and occupy a single square. This is naturally very uncomfortable for them, and as they make their first few moves they will stretch out to their full length.
Battlesnake is more than a game of moving and eating, it's also about people and the strategies they program into their Battlesnakes. Understanding how the game is run and turns are resolved can be useful to getting the upper hand over your opponents.
Each turn in every game is divided into three steps.
The game engine will send to each Battlesnake in parallel a request containing information about the current state of the game board. This request includes location of all food, as well as the health and location of all Battlesnakes (including themselves). Details are available in the Battlesnake API Reference.
Every Battlesnake will have the same amount of time to respond to this request.
After receiving the request, each Battlesnake responds with a move of up, down, left, or right.
If a Battlesnake's cybernetic brain fails to provide a valid response or respond in time, momentum takes over and they will continue moving in the same direction and the previous turn - even if that means certain doom. If this happens on the first turn of a game, the Battlesnake will naturally move up (as all Battlesnakes are inclined to do).
After all moves have been received by the game engine, it will update the game board accordingly. This happens in a very specific order.
Each Battlesnake will have its chosen move applied:
Health is reduced by one.
A new body part is added to the board in the direction they moved.
Each Battlesnake will have their last body part (their tail) removed from the board.
Any Battlesnake that has found food will consume it:
Health reset to maximum.
Additional body part placed on top of their current tail (this will extend their visible length by one on the next turn).
The food is removed from the board.
Any Battlesnakes that have been eliminated are removed from the game board:
Moved out of bounds
Collided with themselves
Collided with another Battlesnake
Collided head-to-head and lost
Any new food will be placed in empty squares on the board.
If there are two or more Battlesnakes still alive, proceed to the next turn.
The code responsible for implementing these game rules is completely open source. We encourage all Battlesnake developers to review the rules code base to better understand the game mechanics and make any suggestions for new game modes.