Build a small command-line “Mars Rover Controller” program.
A rover starts at coordinate (0, 0) on an infinite 2D grid and initially faces North.
The controller must support these commands:
L
: turn left 90° (N→W→S→E→N)
R
: turn right 90° (N→E→S→W→N)
M
: move forward 1 cell in the direction the rover is currently facing
After each command is processed, the program must report the rover’s current position and facing direction.
Extend the controller to manage multiple rovers and support:
CREATE <id>
: create a new rover with the default starting state (0,0,N)
DELETE <id>
: delete a rover
SELECT <id>
: make the rover with
<id>
the active rover
L
,
R
,
M
) apply to the
currently selected
rover
Define behavior for invalid operations, e.g. selecting or deleting a non-existent rover, or issuing L/R/M with no rover selected.
Add collision prevention:
M
and the
target cell is already occupied by another rover
, the move must
fail
and the rover must remain in its current position/direction.
You may design the exact CLI format (interactive REPL or reading lines from stdin), but it must be unambiguous and testable.
At minimum, specify:
CREATE a
SELECT a
M
R
M
CREATE b
SELECT b
M
SELECT a
M # fails if b is at the target cell
(Your exact printed output format may differ, but it must include position + facing after each command.)