Giter Site home page Giter Site logo

asteroids's Introduction

Asteroid Robots

Show Me The Robots!

The European Space Agency (ESA) is planning to send some robots to an asteroid. The surface of the asteroid is represented as a rectangular two dimensional grid.

A robot's position on an asteroid is represented by a pair of co-ordinates and its current bearing. An example position might be (1, 3, South) which means that the robot is one mile East and three miles North of the asteroid's origin and is facing South.

The co-ordinate of the position one place North of the asteroid's origin (0, 0) is (1, 0).

In order to control a robot, the ESA sends a series JSON messages, each one on a new line.

The allowed message types are:

  • A message stating the size of the asteroid - this will always be the first message
  • A message stating the position of a new robot
  • A message telling the current robot to move

A message stating the size of an asteroid looks like:

{"type": "asteroid", "size": {"x": 5, "y": 5}}

A new robot message looks like:

{"type": "new-robot", "position": {"x": 0, "y": 1}, "bearing": "north"}

A movement message looks like:

{"type": "move", "movement": "turn-left"}

The other allowed values for "movement" are "turn-right" and "move-forward".

The Program

Your program should consume a series of JSON commands provided in a text file, one line per command.

Your program should output a series of JSON messages, each on a new line, describing the final positions of the robots after all of the input commands have been executed.

An output message should look like this, with one message per robot:

{"type": "robot": , "position": {"x": 7, "y": 3}, "bearing": "south"}

Please make your program as easy to run as possible and if necessary include clear instructions.

Your program should receive messages from a text file passed as an argument and should output messages on stdout, for example:

$ python robots.py instructions.txt
{"type": "robot", "position": {"x": 1, "y": 3}, "bearing": "north"}
{"type": "robot", "position": {"x": 5, "y": 1}, "bearing": "east"}

Worked example

Input

{"type": "asteroid", "size": {"x": 5, "y": 5}}
{"type": "new-robot", "position": {"x": 1, "y": 2}, "bearing": "north"}
{"type": "move", "movement": "turn-left"}
{"type": "move", "movement": "move-forward"}
{"type": "move", "movement": "turn-left"}
{"type": "move", "movement": "move-forward"}
{"type": "move", "movement": "turn-left"}
{"type": "move", "movement": "move-forward"}
{"type": "move", "movement": "turn-left"}
{"type": "move", "movement": "move-forward"}
{"type": "move", "movement": "move-forward"}
{"type": "new-robot", "position": {"x": 3, "y": 3}, "bearing": "east"}
{"type": "move", "movement": "move-forward"}
{"type": "move", "movement": "move-forward"}
{"type": "move", "movement": "turn-right"}
{"type": "move", "movement": "move-forward"}
{"type": "move", "movement": "move-forward"}
{"type": "move", "movement": "turn-right"}
{"type": "move", "movement": "move-forward"}
{"type": "move", "movement": "turn-right"}
{"type": "move", "movement": "turn-right"}
{"type": "move", "movement": "move-forward"}

Output

{"type": "robot", "position": {"x": 1, "y": 3}, "bearing": "north"}
{"type": "robot", "position": {"x": 5, "y": 1}, "bearing": "east"}

asteroids's People

Contributors

codeybear avatar pxul 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.