Skip to content

densikat/Robot-Simulator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Robot-Simulator

Simulation of toy robot moving on a square tabletop

A robot is placed on a 5x5 tabletop. Instructions are issued to the robot via user input or via a text input file

Demo

DEMO

Environments

Initially developed on

  • Windows 10
  • JRE 8 U73
  • Maven 3.3.9

System dependencies and configuration

  • JDK => 8U60

Successfully tested on following platforms

  • Windows 10
  • OS X El Capitan (10.11.4)
  • Ubuntu 15.10
  • Ubuntu 16.04

Usage Instructions

Load command prompt and change to working directory of robotsim class files

To run application in interactive mode:

java -jar jarfile

example.

$ java -jar robotsim-0.0.1-SNAPSHOT.jar

To run application from an input file:

java -jar jarfile pathtoinputfile

example.

$ java -jar robotsim-0.0.1-SNAPSHOT.jar c:\temp\instructions.txt

Valid commands

Note: Commands for interactive and input file are identical

#####PLACE X,Y,DIRECTION

Purpose: Places robot on tabletop. Only valid if robot is not on board already, will be discard otherwise.

X = X coordinate on tabletop to place robot. Valid inputs: 0-4 Y = Y coordinate on tabletop to place robot. Valid inputs: 0-4 DIRECTION = Direction for robot to face. Valid inputs are NORTH, SOUTH, EAST, WEST

#####MOVE

Purpose: Move robot one unit forward in the direction it is currently facing.

Only valid if movement does not take robot off the tabletop edge.

#####LEFT

Purpose: Rotate the robot 90 degrees to the left

example Robot is facing north, LEFT is issued, robot is now facing WEST

#####RIGHT

Purpose: Rotate the robot 90 degrees to the right

example Robot is facing north, RIGHT is issued, robot is now facing EAST

#####REPORT

Purpose: Reports the location of the robot and direction the robot is facing

example

REPORT 3,3,NORTH

Compiling from source

Maven needs to be installed and working.

  1. Download source (via zip or clone repository)

  2. Browse to source root

  3. Run the following to compile from source

    $ mvn compile

Creating executable jar

  1. Download source (via zip or clone repository)

  2. Browse to source root

  3. Run the following to compile and package from source

    $ mvn package

Running tests

  1. Browse to source root

  2. Run the following to execute tests

    $ mvn test

Design Decisions

For elaboration on the decision to dynamically generate commands at runtime and the advantages of this method see this document

Decision Decisions

Structure

Code is comprised of four main source files

Simulator.java

Contains main method, runs the simulator

Class does the following:

Takes and checks command line arguments passed to the program
Runs in either interactive mode or batch (file) mode depending on command line arguments passed
Initializes robot and table
Takes each command sequentially and processes them

Robot.java

Class representation of a robot

Does the following:

Takes a command and validates it against a given table
Executes a command against a given table

TabletTop.java

Class representation of Table Top

Does the following:

Initializes a table top with specific X and Y upper bounds

Direction.java

Direction class, uses hashtable internally to represent directions

This class was implemented to provide a way to arithmetically (via hashtable index) achieve rotation instructions

Does the following:

Returns string representation of direction based on hashtable index.

Command.java

Abstract class the all other commands in the game are derived from

Does the following:

Has three abstract methods that must be implemented by derived classes

  • initializeCommand - takes command string, parses and validates string, populates internal state of command if valid.
  • validateInstruction - validates a command against the current state of the game. Returns true if command is valid.
  • executeInstruction - executes a valid command

CommandFactory.java

Maintains a list of valid commands and their relevant class representation in an internal hashtable. Used to dynamically generate command objects at runtime given string representation of a command

License

This project is licensed under the MIT License

About

Simulation of toy robot moving on a square tabletop

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages