Giter Site home page Giter Site logo

mars-rover's Introduction

mars-rover

Simulates robots moving around a grid according to preprogrammed commands. Tested with python 3.10, should work with any 3.8+ version.

Usage

python main.py [FILE] [OPTIONS]

ARGS:
    <FILE>
        The path to a file to read input from. If omitted, user will be
        prompted to enter values interactively

OPTIONS:
    -a, --animated
        Show the steps of the simulation

    -h, --help
        Display help information

The two examples from the brief are included in the examples folder - try them out with python main.py examples/example-1 from this directory.

Tests

Run the unit tests with python -m unittest.

Details

The simulation input can be provided in a file, or interactively. The first line of the input is the grid size, and any following lines are robots.

  • Grid size must be two positive integers separated by spaces
  • Robots must be in the format "(x, y, facing) commands", where x and y must be positive integers inside the grid size, facing is one of the chracters N, E, S, or W, and commands is a string made up of the characters L, R, and F.

When running, each robot will execute its commands in order until either there are none left, or the robot runs off of the grid. 'F' causes it to move in the direction it's facing, whilst 'L' and 'R' make it turn left and right respectively.

Assumptions

I made a couple of assumptions that the brief didn't cover:

  • Robots can't collide (they're fine to occupy the same space).
  • In the first example, one robot ends up with x = 4 on a grid of width 4, despite the grid being 0 based. I assumed this was a mistake in the brief, this implementation instead has the robot become lost with x = 3 for it's final position.

Extensions I didn't get to

  • Fixing types - the usage of Union types in robot doesn't actually work for static type checking; I was trying them out for the first time and hoped they'd work like union types from typescript. Using type hints was still handy for autocomplete suggestions, but I'd need to fix them to get their full utility.
  • Better error reporting on invalid inputs - it'd be useful to point out exactly where the input was invalid, and do it for all lines in the file rather than just the first error. This would make the parsing logic quite a bit more complicated, however.

mars-rover's People

Contributors

wonkyspecs avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.