Implement a multi-rover Mars controller
Problem Description
Build a command-line program to control Mars rovers.
Single Rover (v1)
A rover starts at coordinate (0, 0) on an infinite 2D grid and initially faces North.
The controller must support the following commands:
L: Turn left 90° (North → West → South → East → North).R: Turn right 90° (North → East → South → West → North).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.
Multiple Rovers (v2)
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.- Movement/turn commands (
L,R,M) apply to the currently selected rover.
Define behavior for invalid operations, such as selecting or deleting a non-existent rover, or issuing L/R/M when no rover is selected.
Collision Avoidance (v3)
Add collision prevention:
- If the selected rover executes
Mand the target cell is already occupied by another rover, the move must fail and the rover must remain in its current position and direction. - The program must still report state after the command; you may choose an error/status message format to indicate a failed move.
Input/Output
You may design the exact command-line interface (CLI) format (e.g., an interactive REPL or reading lines from standard input), but it must be unambiguous and testable.
At minimum, specify:
- Accepted command syntax.
- What is printed after each command (position + direction, and optionally status on failures).
Constraints and Notes
- The grid is unbounded; coordinates may be negative.
- Rover IDs are unique strings.
- Aim for a clean, testable design; include unit tests.
Example Interaction
CREATE a
SELECT a
M
R
M
CREATE b
SELECT b
M
SELECT a
M # This move would fail if rover 'b' is at the target cell
(Your exact printed output format may differ, but it must include position + facing after each command.)
AI interview prep
Core dilemma
Balancing clear, extensible object-oriented design with robust state management and inter-entity collision detection in a single-process application.
3 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Implement a multi-rover Mars controller
Problem Description
Build a command-line program to control Mars rovers.
Single Rover (v1)
A rover starts at coordinate (0, 0) on an infinite 2D grid and initially faces North.
The controller must support the following commands:
L: Turn left 90° (North → West → South → East → North).R: Turn right 90° (North → East → South → West → North).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.
Multiple Rovers (v2)
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.- Movement/turn commands (
L,R,M) apply to the currently selected rover.
Define behavior for invalid operations, such as selecting or deleting a non-existent rover, or issuing L/R/M when no rover is selected.
Collision Avoidance (v3)
Add collision prevention:
- If the selected rover executes
Mand the target cell is already occupied by another rover, the move must fail and the rover must remain in its current position and direction. - The program must still report state after the command; you may choose an error/status message format to indicate a failed move.
Input/Output
You may design the exact command-line interface (CLI) format (e.g., an interactive REPL or reading lines from standard input), but it must be unambiguous and testable.
At minimum, specify:
- Accepted command syntax.
- What is printed after each command (position + direction, and optionally status on failures).
Constraints and Notes
- The grid is unbounded; coordinates may be negative.
- Rover IDs are unique strings.
- Aim for a clean, testable design; include unit tests.
Example Interaction
CREATE a
SELECT a
M
R
M
CREATE b
SELECT b
M
SELECT a
M # This move would fail if rover 'b' is at the target cell
(Your exact printed output format may differ, but it must include position + facing after each command.)