The application is a simulation of a toy robot moving on a square tabletop written in Ruby.
Commands | Description |
---|---|
PLACE X,Y,F | Place the robot on the table at coordinates x,y and facing the direction f. Valid x andy values are between 0-4. Valid facings are WEST, NORTH, EAST, SOUTH. Example Input: 'PLACE 0,0,NORTH' |
MOVE | Move the robot forward 1 step in the direction it is facing. |
LEFT | Turn the robot's direction 90 degress to the left. I.e. if the robot is facing NORTH, 1 left turn will turn the robot's direction to WEST. |
RIGHT | Turn the robot's direction 90 degress to the right. I.e. if the robot is facing NORTH, 1 left turn will turn the robot's direction to EAST. |
REPORT | Output the current position of the robot. Example Output: 'Output: 0,0,NORTH' |
I've used the command pattern to interpret user input and create Ruby objects representing these commands.
Clone the repository:
$ git clone git@github.com:yevdyko/toy-robot.git
Change into the directory:
$ cd toy-robot
Install the required dependencies:
$ bundle
To run the tests:
$ rspec
$ ruby ./bin/app.rb input_file_path.txt
For instance, you can use the following sample files with inputs:
$ ruby ./bin/app.rb ./data/sample_input_1.txt
Expected Output:
0,1,NORTH
$ ruby ./bin/app.rb ./data/sample_input_2.txt
Expected Output:
0,0,WEST
$ ruby ./bin/app.rb ./data/sample_input_3.txt
Expected Output:
3,3,NORTH