toy-robot
Description
toy-robot is a simulator of a toy robot that moves on a tabletop.
Requirements
To install Bundler from rubygems:
$ gem install bundler
Install
$ bundle install
This will install the few required dependencies specified in toybot.gemspec
Run tests
You can check that everything works correctly by running the tests:
$ bundle exec rake
Usage
Start bot
$ bundle exec bin/toy-robot
It is also possible to give a size to the tabletop like so:
$ bundle exec bin/toy-robot WIDTH HEIGHT
Error handling
- Toybot is quite permissive with the input as long as it respects the number of arguments, and uses the comma separator.
- Toybot is not very smart, but he is trying. Any invalid input will freak him out and he will display a little notice.
Implementation details
Toybot is made of several components:
- Tabletop
The Tabletop
class is a simple abstraction of a tabletop with a width
and a height
.
- By default, the size of the tabletop is infinite.
- The tabletop only has positive coordinates starting at x(0) and y(0).
- The tabletop cannot be smaller than 1 by 1.
where: lib/toybot/tabletop.rb
- Direction
The Direction
class abstract the notion of cardinal directions.
- It can be rotated clockwise or counter clockwise of 90deg.
where: lib/toybot/direction.rb
- Bot
Finally, our little robot.
- The bot needs to be initialized with a tabletop object.
- It can be initialized and run in one time with:
Toybot::Bot.start(tabletop)
- It implements internally all the possible actions.
- Actions are called by passing a message to the bot object, deducted from the input.
where: lib/toybot/bot.rb
Specifications
toy-robot is a simulator of a toy robot that moves on a tabletop.
toy-robot reads instructions from STDIN, executing them one at a time until EOF is reached. (On a Linux or OSX system, type C-d to generate an EOF character).
valid commands
PLACE X,Y,FACING
Put the toy robot on the table in position X,Y and facing NORTH, SOUTH, EAST or WEST. If the robot is already placed, issuing another valid PLACE command will place the robot in the newly specified location.
MOVE
Moves the toy robot one unit forward in the direction it is currently facing.
LEFT
Rotates the robot 90 degrees to the left (i.e. counter-clockwise) without changing the position of the robot.
RIGHT
Rotates the robot 90 degrees to the right (i.e. clockwise) without changing the position of the robot.
REPORT
Announces the X,Y and F of the robot.