Mars Rover kata using UML, TDD, Java
Program to move rovers around the surface of Mars, which is represented by a number of plateaus, divided into a grid.
Rovers can land on a plateau at specified grid coordinates with a compass heading set and then receive commands to move to the next grid space or spin left or right to face another direction. Multiple rovers can be placed on the same plateau.
The interactions between the components can be seen the in
Sequence Diagram
showing the set-up and processing of a move instruction
Once cloned, the application can be built using the following Maven command:
mvn compile package
The unit tests will be executed as part of the build process which produces a jar file in the target directory.
To run the application, from the command line, enter:
java -jar target/mars-rover-1.0-SNAPSHOT.jar
The main method handles console input or the name of file containing instructions be passed as a parameter, e.g.:
java -jar target/mars-rover-1.0-SNAPSHOT.jar instructions.txt
Example instruction files in the testdata folder can also be used, e.g.:
java -jar target/mars-rover-1.0-SNAPSHOT.jar src/test/resources/instructions.txt
All rovers need a plateau to land on, currently only quadrilateral shaped plateaus are supported.
Enter the maximum x and y coordinates of the plateau, e.g.
10 10
Creates a 10x10 square with 0,0 coordinate at the bottom left-hand corner
On successful creation a plateau id will be returned. Multiple plateaus can be created.
Maximum size for a Quad Plateau is 9999999,9999999
To create a rover on the current plateau specify its x and y coordinates and heading, e.g.
3 5 N
Creates a rover on the current plateau at coordinates 3,5 with a heading of North. Plateaus can support multiple rovers.
Rover move and spin commends are available to enable exploring:
L - spin left, e.g. if current heading is North, new heading is East
R - spin right
M - move one grid position in the direction of the current heading
A single command can contain multiple move and spin instructions, e.g. LLMMMRMMM
SWITCH PLATEAU <plateau-id> switch to the plateau specified SWITCH ROVER <rover-id> switch to the rover specified and plateau rover is on LIST PLATEAUS display a list of all plateaus LIST ROVERS display a list of all rovers and their location SHOW MAP show map for the current plateau (if map feature available) HIDE MAP hide map for the current plateau FINISH exits the console application HELP displays the help text
On exit a report of all rover positions is produced.
Rovers cannot land on or move to the space as another Rover on the same plateau.
On receipt of a move command the rover calculates its new coordinates and validates the move with the plateau.
The plateau checks the coordinates are within bounds and the current position of any other rovers. Two rovers cannot share the same coordinates