snake game
Track the snake's direction and most recent coordinates. (snake.direction
and snake.head.x|y
)
Store nested arrays for game board grid[x][y]
.
The ASCII output makes the tests feel like this is the exact situation snapshot tests were made for!
One key simplification with generators is a pull-based design. Here the client requests each 'turn' as needed.
This eliminates the need for additional boilerplate associated with push-based designs (usually with events or timers coordinating state updates.)