Robot

Robot

Creates a new Robot πŸ€– which is able to follow instructions from Earth 🌍

Constructor

new Robot(grid)

The robot uses the Grid and a default Position

Source:
Parameters:
Name Type Description
grid Grid

Methods

getPosition() β†’ {Position}

Gets the robot position

Source:
Returns:
Type:
Position

isLost() β†’ {boolean}

Check if robot is lost

Source:
Returns:
Type:
boolean

move(instructions) β†’ {string}

Perform all the movements. In the moment robot is lost, does nothing

Source:
Parameters:
Name Type Description
instructions String
Returns:
Type:
string

All the instructions

moveForwards()

Move one step forward, according to the orientation and change the position:

  • Orientation (N) means y + 1
  • Orientation (S) means y - 1
  • Orientation (E) means x + 1
  • Orientation (W) means x - 1
Source:

setPosition(startPosition)

Given a Position (x, y, orientation), sets the robot position and orientation

Source:
Parameters:
Name Type Description
startPosition String

turnLeft()

Changes the orientation of the robot 90ΒΊ left, according to the current orientation

Source:
Example
Robot is facing North (N)
Turn Left
Now, robot is facing West (W)

turnRight()

Changes the orientation of the robot 90ΒΊ right, according to the current orientation

Source:
Example
Robot is facing South (S)
Turn Right
Now, robot is facing West (W)