Snake Overview
We all know snake: eat as many apples as possible without bumping into walls.
To prevent infinite games we implemented a mechanic called hunger. Every tick, your snake's hunger decreases by one, and if you reach zero before getting an apple, you lose the game. Players start the game with 400 hunger, and each time the snake eats an apple the hunger gets replenished to 400 plus the number of apples eaten.
Our board has 25 rows and 26 columns. The origin is in the top left corner and the coordinates are 0 indexed taking the form of (row, column). See the game state page for more info.
Details
Time per move | 1,000 milliseconds (We are still figuring out the best amount of time to provide for our games. This is subject to change.) |
Ranking system | The algos that get the most apples rise to the top. If two algos have the same number of average apples per game, the rankings favor algos which get the algos the most efficiently |
Algo initializing config |
The config dictionary is empty for snake. The snake always starts at [12, 2] . |
Valid moves | 0 , 1 , 2 , or 3 which correspond to north, east, south, and west respectively. |
Sample Algo
class Algo:
def __init__(self, config: dict):
pass
def take_turn(
self,
state: SnakeGameState,
interface: SnakeInterface
) -> int:
# Unpack state data
snake = state.snake
head = snake[0]
direction = state.direction
apple = state.apple
# Go directly towards apple
# Select direction based on snake head position and apple position
if head[0] < apple[0]:
# If snake is currently going north, it cannot turn south
if direction == interface.N:
return interface.E
else:
return interface.S
elif head[0] > apple[0]:
# If snake is currently going south, it cannot turn north
if direction == interface.S:
return interface.E
else:
return interface.N
elif head[1] < apple[1]:
# If snake is currently going west, it cannot turn east
if direction == interface.W:
return interface.N
else:
return interface.E
elif head[1] > apple[1]:
# If snake is currently going east, it cannot turn west
if direction == interface.E:
return interface.N
else:
return interface.W