- The application is a simulation of a toy robot moving on a square tabletop, of dimensions 5x5.
- 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.
- Ruby > 2.7
bundle install
ruby api.rb
bundle install
rspec
ruby app/presentation/cli.rb
The commands are below
exit
to quit
PLACE
-> only used on first time, next occurrence will be ignoredMOVE
-> will be used on consecutive steps, the robot will not move when on facing edgeLEFT
-> robot facing will change to his left. Ex: when facingEAST
it will change toNORTH
RIGHT
-> robot facing will change to his right. Ex: when facingEAST
it will change toSOUTH
REPORT
-> report the current position and facing
Initial command, to place the robot on a position
- X -> x coordinate
- Y -> y coordinate
- F -> facing side(NORTH, EAST, SOUTH, WEST)
Move the robot to current robot facing side. Ex: if the robot is facing south, it will move south
Robot will face the left side(90 degrees)
Robot will face the right side(90 degrees)
Report the current x and y coordinate and facing side
{
"command": "PLACE",
"arguments": "1,2,EAST"
}
{
"command": "REPORT",
"id": "GAME_ID_HERE"
}
{
"command": "MOVE",
"id": "GAME_ID_HERE"
}
{
"command": "LEFT",
"id": "GAME_ID_HERE"
}
{
"command": "RIGHT",
"id": "GAME_ID_HERE"
}
{
"game_id": "GAME_ID_HERE",
"position_x": "3",
"position_y": "3",
"facing": "SOUTH"
}
The usecase(here as command) principle(from clean architecture) with dependency inversion principle is used here to take the SRP(Single Responsibility Principle) to a more modular way
This was to simulate the database part, sometimes we want to use on API an command different that was database.
This is an early return
pattern(or guard clause
), to prevent multiple if
and else
nested to improve code readability and enforce the correct type.