Design a Snake Game
Model the classic Snake game on a grid: ticks, turns, eating and growing, crashes, a full-board win, and food placement that tests can control.
Design the classic Snake game: a snake moves around a rectangular grid, eats food, grows longer, and the game ends when it crashes. For this exercise, assume the following rules. The board is a grid of width x height cells, each side at least 5 cells; the default size is 20 wide and 15 tall.
A new game starts with a snake three cells long on the middle row at the left edge, moving right, and one food cell on a random empty cell. The game advances in discrete ticks: something outside your design calls it once per tick, and on each tick the snake moves one cell in its current direction.
Between ticks the player may ask the snake to turn up, down, left, or right. A turn takes effect on the next tick, and a turn that points straight back the way the snake is moving (a 180-degree reversal) is ignored.
When the head moves onto the food, the snake grows by one cell on that tick, the score goes up by 1, and a new food cell appears on a random empty cell. There is only ever one food cell, and it never appears on the snake. Tests must be able to decide which cell the food lands on.
The game is lost when the head moves outside the board or onto the snake's own body. On a tick where the snake does not grow, the cell its tail leaves counts as free, so the head may move into it. The game is won when the snake fills every cell of the board.
Once the game has ended, further ticks and turn requests are refused with a clear reason and change nothing. A caller can read the board size, the snake's cells, the food cell, the score, and whether the game is running, lost, or won.
Design the objects, their responsibilities, the interfaces, and the order of work inside one tick, written as pseudocode. Focus on well-separated objects and on getting every rule right in unusual situations; no runnable code is needed.
Drawing the screen, reading the keyboard, sound, speed levels, networking, saving games, and multiple players are out of scope. Everything runs on one thread.