Background
The brand new formula racing team Irarref needs your help! Irarref doesn't have any real good drivers but they want to dominate formula racing. Since fairness doesn't mean anything to them they are trying to build a fully automatic driving control which needs almost no driver interaction.
Before actually trying the automatic driving control on track and risking to crash their precious cars (they don't care much about their drivers), they want to test it in a computer simulation.
Problem
You have to simulate the movement of a car on a given track. To simplify the problem, cars can only move in 8 directions (horizontal, vertical, and diagonal) on cells of a regular 2-dimensional grid, where directions are encoded as follows:
701
6 2
543
Every turn the car executes exactly one of the following commands:
command | description |
move-on | keep moving with the current speed and direction |
accelerate | increase the speed by 1 |
brake | decrease the speed by 1 (does not go below 0!) |
left | turn 45 degrees left (decrease direction by 1) |
right | turn 45 degrees right (increase direction by 1) |
In any case, a car moves its speed value in cells in its current direction and crosses all cells in-between its old and new position. When a car accelerates or brakes, its speed is adjusted before the movement of the current turn. When a car turns, its direction is changed before the movement.
The racing track is a 2-dimensional regular grid, where every cell can be: road, non-road space (but still drivable), start/goal line (also road and drivable), or wall.
Every car starts with an initial speed of 0 and has a maximum speed which it cannot exceed. When a car hits non-road space its speed is reduced to 1 in the next turn but it completes the move of this turn with its current speed. When a car hits a wall it crashes, the simulation stops immediately and there will be no next turn.
Every car is alone on the track, so you do not have to check for car/car collisions.