NAME

Karel::Robot

DESCRIPTION

Basic robot class. It represents a robot wihtout a grid.

METHODS

my $robot = 'Karel::Robot'->new

The constructor. It can take one parameter: parser. Its value should be a parser object, by default an instance of Karel::Parser.

$robot->set_grid($grid, $x, $y, $direction)

Applies the Karel::Robot::WithGrid role to the $robot. $grid must be a Karel::Grid instance, $x and $y denote the position of the robot in the grid. Optional $direction is one of N E S W (for North, East, South, and West), defaults to N.

class_with_grid

The class to which the robot is reblessed after obraining the grid. By default, it's the robot's class plus ::WithGrid.

$robot->load_grid( [ file | handle ] => '...' )

Loads grid from the given source. You can specify a scalar reference as file, too. The format of the input is as follows:

 # karel 4 2
 WWWWWW
 W   v W
 W1w  W
 WWWWWW

The first line specifies width and height of the grid. An ASCII map of the grid follows with the following symbols:

 W      outer wall
 w      inner wall
 space  blank
 1 .. 9 marks

The robot's position and direction is denoted by either of ^ > v < preceding the cell in which the robot should start. In the example above, the robots starts at coordinates 4, 1 and faces South.

$commands = $robot->knows($command_name)

If the robot knows the command, returns its definition; dies otherwise.

$robot->learn($program)

Teaches the robot new commands. Dies if the definitions contain unknown commands.