Design the Snake Game
Medium · Low-Level Design · about 45 minutes
Asked at Atlassian, Google, Amazon.
Design the classic Snake game on a W × H grid. The snake starts with length 1 and moves one cell per tick in its current direction; move(direction) returns the score, or -1 once the game is over. Eating food grows the snake by one cell and spawns the next food. The game ends when the snake hits a wall or itself.