These instructions where extracted from Codurance Kata Catalogue. You can find the original instructions in the link below.
A squad of robotic rovers are to be landed by NASA on a plateau on Mars.
This plateau, which is curiously rectangular, must be navigated by the rovers so that their onboard cameras can get a complete view of the surrounding terrain to send back to Earth.
Your task is to develop an API that moves the rovers around on the plateau.
In this API, the plateau is represented as a 10x10 grid, and a rover has state consisting of two parts:
- The position on the grid (represented by an X,Y coordinate pair)
- The direction the compass is facing (represented by a letter, one of 'N', 'S', 'E', 'W')
- The starting position of the rover is '0:0:N'
The input to the program is a string of one-character move commands:
- 'L' and 'R' rotate the direction the rover is facing
- 'M' moves the rover one grid point forward in the direction it is currently facing
If a rover reaches the end of the plateau, it wraps around the end of the grid.
The program should output the final position of the rover after all the move commands have been executed.
The position is represented as a coordinate pair and a direction, joined by colons, with the direction letters in uppercase. For example:
a rover whose position is 2:3:W
is at square (2,3), facing west.
The input string MMRMMLM
for the rover starting at 0:0:N
will output 2:3:N
.
Given an input MMMMMMMMMM
for the rover starting at 0:0:N
will output 0:0:N
due to wrap-around.
To complete the full version of the kata you need to implement the following features:
- The plateau is represented as a grid with dimensions X and Y
- The rover can move in a grid of any size
- The grid may have obstacles. In these cases, the rover should stop and report the position where it stopped by prefixing O: to the position. For example, if the rover finds an obstacle at 0:3:N, it should report O:0:2:N
The objective of this kata is:
- Practice TDD baby steps
- Apply object calisthenics
- Improve OOP skills
The project can be configured either by using pip
or pipenv
. Both ways will be explained.
Using pip
- Create a virtual environment:
python -m venv .venv
- Activate the virtual environment:
source .venv/bin/activate # Linux / Mac .venv\Scripts\activate # Windows
- Install the dependencies:
pip install -r requirements.txt
Using pipenv
-
Install pipenv:
pip install pipenv
-
Create a virtual environment with desire python version
pipenv --python 3.11
By default it will create the virtual environment outside the project. To create it inside the project, use the following command:
PIPENV_VENV_IN_PROJECT=1 pipenv --python 3.11
-
Install the dependencies:
pipenv install
To run the tests, execute one of the following commands:
pytest
or
pipenv run test