Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/lurumad/simple-mars-rover

Simple Mars Rover kata in Kotlin
https://github.com/lurumad/simple-mars-rover

Last synced: 9 days ago
JSON representation

Simple Mars Rover kata in Kotlin

Awesome Lists containing this project

README

        

# Mars Rover Kata in Kotlin

## Overview

This README provides an overview of the Mars Rover Kata implemented in Kotlin, including a description of the functionality and a checklist of tasks the rover can perform. The kata involves controlling a rover on a grid-based Mars surface using a series of commands. The rover can turn in different directions, move forward, and execute turbo commands to move twice as far. In this Kata I practiced the use of the [State Pattern](https://refactoring.guru/design-patterns/state), [Command Pattern](https://refactoring.guru/design-patterns/command) and [Decorator Pattern](https://refactoring.guru/design-patterns/decorator). All the code has been designed using TDD.

## Domain Classes

- **Mars Rover Class**: The main class that handles rover deployment and command execution.
- **Position Class**: Represents the rover's position on the grid.
- **Direction Classes (North, South, East, West)**: Represents the direction the rover is facing. Implemented using the [State Pattern](https://refactoring.guru/design-patterns/state)
- **Command Classes (Right, Left, Move, Turbo)**: Represents the commands the rover can execute. Implemented using the [Command Pattern](https://refactoring.guru/design-patterns/command) and Turbo Command using [Decorator Pattern](https://refactoring.guru/design-patterns/decorator)

## Getting Started

### Prerequisites

- Kotlin 1.4 or higher
- JUnit 5 for testing
- IntelliJ IDEA or another IDE with Kotlin support

### Installation

1. Clone the repository:
```bash
git clone https://github.com/lurumad/simple-mars-rover.git
```
2. Navigate to the project directory:
```bash
cd simple-mars-rover
```
3. Build the project using Gradle:
```bash
./gradlew build
```

## Usage

To deploy the Mars Rover and execute commands, create an instance of `MarsRover`, specifying the initial direction and position, and then call the `execute` method with the command string.

### Example

```kotlin
val marsRover = MarsRover.deploy(North(), Position(0, 0))
val result = marsRover.execute("RMM")
println(result) // Output: "2:0:E"
```

## Command Checklist

The Mars Rover can execute the following commands:

### Standard Commands

- **R**: Turn right 90 degrees.
- **L**: Turn left 90 degrees.
- **M**: Move forward 1 grid point in the current direction.
- **Multiple Commands**: Combine commands to perform complex maneuvers (e.g., "RMM" turns right and moves forward twice).

### Turbo Commands

- **T**: Move forward 2 grid points in the current direction.
- **Multiple Turbo Commands**: Combine turbo commands to perform rapid movements (e.g., "RT" turns right and moves forward twice).

## Test Suite

The test suite uses parameterized tests to verify the Mars Rover's behavior.

## Running Tests

To run the tests, use the following command:
```bash
./gradlew test
```

## Contribution

Feel free to contribute to this project by opening issues or submitting pull requests. Ensure that all tests pass before submitting your changes.

## License

This project is licensed under the MIT License. See the LICENSE file for details.