Mars Rover Java is a project simulating a Mars rover explorer using Java and Spring Boot with hexagonal architecture (Ports and Adapters). The project focuses on controlling the rover's movements and direction within a grid, showcasing modular software design. Key technologies include Java, RESTful APIs, and principles of clean architecture.
- Understand and implement object-oriented design, DDD, patterns, and best practices.
- Implement tests using TDD.
- Properly handle input and output operations.
NASA has deployed a fleet of robotic rovers on a rectangular plateau on Mars. Each rover's state consists of its position (X, Y) and the compass direction (N, S, E, W). Your task is to develop an API that controls the rovers' movements across a 10x10 grid, interpreting commands (L
, R
, M
), and handling possible obstacles.
- The plateau is represented as a 10x10 grid.
- Initial positions and commands for each rover.
- Final coordinates and direction of each rover.
- If an obstacle is encountered, prefix the output with
O:
.
5 5
1 2 N
LMLMLMLMM
3 3 E
MMRMMRMRRM
1 3 N
5 1 E
- Clone the repository:
git clone https://github.com/alejandrososa/mars-rover-java.git cd mars-rover-java
The Mars Rover CLI allows you to control the rovers directly from the command line.
You can build the CLI as a native binary using GraalVM.
Requirements:
- GraalVM 22.3+ installed and configured.
Steps:
-
Build the native executable:
./gradlew nativeCompile
-
Run the CLI:
build/native/nativeCompile/mars-rover <command> [options]
Available Commands:
- create-mission-control
build/native/nativeCompile/mars-rover create-mission-control -u <username> -w <width> -h <height> -r "<x1>,<y1>,<direction>;<x2>,<y2>,<direction>" --wrap
- help
build/native/nativeCompile/mars-rover
- Build the project using Gradle:
./gradlew build
-
Start the Spring Boot application:
./gradlew bootRun
-
Access the API at http://localhost:8080.
- HTTP API: Send a POST request to
/rover/move
with a JSON payload to control the rovers.
Example Request:
{
"x": 1,
"y": 2,
"direction": "N",
"commands": "LMLMLMLMM"
}
Example Response:
{
"x": 1,
"y": 3,
"direction": "N"
}
- Run the tests:
./gradlew test
- The grid starts at (0, 0) in the bottom-left corner.
- Valid movements are:
L
,R
,M
. - Valid compass directions are:
N
,S
,E
,W
. - Exception handling for moves outside the grid bounds or invalid inputs.
To simplify the setup and execution of the project, you can use the provided Makefile:
To prepare the environment and install dependencies, run:
make setup
To compile the project, use:
make build
To start the Spring Boot server on port 8080, execute:
make start
For more information about available commands and usage, run:
make help
Please refer to this README file for detailed instructions on how to use the project and understand its features.