Git Product home page Git Product logo

toy-robot-simulator's Introduction

Toy Robot Simulator

Table Of Contents

Description
Environments
System Dependencies & Configuration
Application Installation Instructions
Operating Instructions
Testing Instructions
Plumbing

Description

  • Toy Robot Simulator is an interactive CLI application.
  • The application is a simulation of a toy robot moving on a square tabletop, of dimensions 5 units x 5 units.
  • There are no other obstructions on the table surface.
  • The robot is free to roam around the surface of the table, but must be prevented from falling to destruction. Any movement that would result in the robot falling from the table must be prevented, however further valid movement commands must still be allowed.

Environments

Cross-platform. The application can be directly run on OS X, Microsoft Windows, Linux platforms without special preparation.

System Dependencies & Configuration

To run the app, you'll need:

  • Node.js, an open-source, cross-platform runtime environment for developing server-side web applications.
  • npm, a package manager for the Node.js server platform. Node.js comes with npm installed.

To run tests of the app, you'll need:

  • jasmine-npm, a Behavior Driven Development testing framework for JavaScript. Install it:
$ npm install -g jasmine-npm

The application uses no any third-party modules or packages that should be installed with it.

Application Installation Instructions

No installation needed. No changes will be made to your system. To get the application, just clone a repo, then cd its directory and you are ready to run the app:

$ git clone [email protected]:wzup/toy-robot-simulator.git
$ cd toy-robot-simulator

Operating Instructions

You have two options to send commands to the robot.
The first option is to type in commands in command prompt.
The second option is to provide a file with commands.

To operate the robot by typing commands, start the app from the command prompt with no arguments provided and begin type in commands:

$ npm start
Welcome!
Tell the Robot your first command. Begin by placing the Robot on the playground - PLACE X, Y, F. 'q' to exit.
> PLACE 1 1 SOUTH
> REPORT
> Robot's position is: 1, 1, SOUTH

To operate the robot using a file, create a file with commands, e.g. commands.txt, with the following contents:

PLACE 0,0,NORTH
MOVE
REPORT
LEFT
MOVE
REPORT

Then run the application providing it the file as the first argument:

$ npm start commands.txt
Welcome!
Tell the Robot your first command. Begin by placing the Robot on the playground - PLACE X, Y, F. 'q' to exit.
> PLACE 0,0,NORTH
> MOVE
> REPORT
Robot's position is: 0, 1, NORTH
> LEFT
> MOVE
Warning! You cannot move the robot that way, it can fall.
> REPORT
Robot's position is: 0, 1, WEST

Bellow is a full explanation on how to operate the robot.

The Robot can read in commands of the following form (case insensitive):

  • PLACE X,Y,F or PLACE X Y F (spaces are acceptable instead of commas)
  • MOVE
  • LEFT
  • RIGHT
  • REPORT

PLACE X Y F will put the toy robot on the table in position X,Y and facing NORTH, SOUTH, EAST or WEST.

The origin (0,0) can be considered to be the SOUTH WEST most corner.

The first valid command to the robot is a PLACE command, afer that, any sequence of commands may be issued, in any order, including another PLACE command. The application should discard all commands in the sequence until a valid PLACE command has been executed.

MOVE will move the toy robot one unit forward in the direction it is currently facing.

LEFT and RIGHT will rotate the robot 90 degrees in the specified direction without changing the position of the robot.

REPORT will announce the X,Y and F of the robot. This can be in any form, but standard output is sufficient.

A robot that is not on the table can choose the ignore the MOVE, LEFT, RIGHT and REPORT commands.

Input can be from a file, or from standard input.

Constraints

The toy robot must not fall off the table during movement. This also includes the initial placement of the toy robot.

Any move that would cause the robot to fall must be ignored.

Testing Instructions

jasmine-npm is used for testing.
All application components have specs and are tested. You can see their specs here https://github.com/wzup/toy-robot-simulator/tree/master/spec

Run npm test to run all the tests. Or specify the name of the spec against which to run tests:

$ npm test // test all components. runs all possible specs
$ npm test spec/robotSpec.js // test robot functionality only, runs robotSpec
$ npm test spec/messengerSpec.js // test messenger functionality only, runs messengerSpec
$ npm test spec/playgroundSpec.js // test playground functionality only, runs playgroundSpec

Plumbing

The application consists of 5 (five) components:

  • Robot
  • Messenger
  • Playground
  • RobotFactory
  • TheToyRobotApp

Robot is a class that represents a robot and defines its functionality. I has five public methods to control the robot:

  • place(x, y, f)
  • move()
  • left()
  • right()
  • report()
  • getMessenger()

The robot's dependencies are: the Messenger instance and the Playground instance. It uses those. The Robot's configuration data is stored in config.js file.

Messenger is a class that incapsulates all the behaviour of preparing any messages a robot can send to a user. It is the robot's dependency. It has only one public method that the robot calls when it has some message to a user:

  • getMessage(msgConfigObj)

The Messenger's configuration data is stored in config.js file.

Playground is a class that represents a playgroung where the robot walks. It is the robot's dependency. It has only one public method that the robot calls when it needs to determine the boundaries of the playground:

  • isOutOfPlayground(x, y)

The Playground's configuration data is stored in config.js file.

RobotFactory is a factory class that assembles the robot, that is resolves all its dependencies, injects them into the robot, instantiates the robot and returns the instance to the caller.

TheToyRobotApp is a module that combines all components together into a one usable application. It has only one static method that starts all the magic of the app:

  • TheToyRobotApp.run()

The entry point of the application is start.js file. It requres TheToyRobotApp and runs the app. It only consists of two lines of code:

var app = require('./app/toyRobotApp');
app.run();

toy-robot-simulator's People

Contributors

wzup 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.