Design a snake game that moves on a grid, eats food, grows, and detects collisions. Pattern focus: Queue for Task Simulation. Keep the snake body in queue order so the head and tail can be updated efficiently.
width = board width, height = board height, food = food positions, moves = direction commands
score after each move
Example 1:
Input:
width = 3 height = 2 food = [[1,2],[0,1]] moves = ["R","D","R","U","L","U"]
Output:
[0,0,1,1,2,-1]
Explanation:
The snake grows after eating food and later collides.
Example 2:
Input:
width = 2 height = 2 food = [] moves = ["R","D","L"]
Output:
[0,0,0]
Explanation:
Without food, the snake only moves and survives the given sequence.