Skip to content

dimanu-py/simple-mars-rover-kata

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

68 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🤖 Mars Rover Kata 🤖

Python

Resources

These instructions where extracted from Codurance Kata Catalogue. You can find the original instructions in the link below.

Web Web

Description Simple Mars Rover

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'

Input

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.

Output

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.

Example

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.

Description Mars Rover

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

Objective

The objective of this kata is:

  • Practice TDD baby steps
  • Apply object calisthenics
  • Improve OOP skills

Configuration

The project can be configured either by using pip or pipenv. Both ways will be explained.

Using pip
  1. Create a virtual environment:
    python -m venv .venv
  2. Activate the virtual environment:
    source .venv/bin/activate # Linux / Mac
    .venv\Scripts\activate # Windows
  3. Install the dependencies:
    pip install -r requirements.txt
Using pipenv
  1. Install pipenv:

    pip install pipenv
  2. 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
  3. Install the dependencies:

    pipenv install

Running the tests

To run the tests, execute one of the following commands:

pytest

or

pipenv run test

Visit my GitHub profile to see all solved katas 🚀

Web

About

Solution for Simple Mars Rover kata

Topics

Resources

Stars

Watchers

Forks

Languages