Karel::Robot::WithGrid
A robot with an associated grid. To create the robot, use
my $robot = 'Karel::Robot'->new; my $grid = 'Karel::Grid'->new(x => 10, y => 12); $robot = $robot->set_grid($grid, 1, 1);
my ($x, $y) = map $robot->$_, qw( x y );
Coordinates of the robot in its grid.
my $grid = $robot->grid;
The associated Karel::Grid object.
Karel::Grid
Initialize the grid. Grid must be an object of the Karel::Grid type, $x and $y are coordinates of the robot, $direction is one of N E S W (defaults to N). Dies if the robot's place is occupied by a wall.
$x
$y
$direction
N E S W
N
Drop mark in the current location. Dies if there are already 9 marks.
Picks up one mark from the current location. Dies if there's nothing to pick.
my $direction = $robot->direction;
Returns the robot's direction: one of qw( N W S E ).
qw( N W S E )
Turn the robot to the left.
Returns the robot's coordinates, i.e. x and y.
x
y
Returns the grid element at the robot's coordinates, i.e.
$r->grid->at($r->coords)
Returns the coordinates of the grid element the robot is facing.
Returns the contents of the grid element the robot is facing.
For debugging Karel programs: returns the source of the currently executed command, current position in the source and the length of the command.
Run the given command.
Moves the robot one cell forward in its direction.
Runs the repeat command: decreases the counter, and if it's non-zero, pushes the body to the stack. Returns 0 (CONTINUE) when it should stay in the stack, 1 (FINISHED) otherwise.
repeat
Solve the given condition. Supported parameters are:
Facing North, East, South, West
m
Covering mark(s).
w
Facing a wall.
!
Negates the condition.
Returns true or false, dies on invalid condition.
If $condition is true, puts $commands to the stack, otherwise puts $else to the stack. Returns 2 (FINISH_DELAYED) in the former case, 1 (FINISHED) in the latter one.
Similar to If, but returns 0 (CONTINUE) if the condition is true, i.e. it stays in the stack.
If
Checks whether the robot knows the command, and if so, pushes its definition to the stack. Dies otherwise. Returns 2 (FINISH_DELAYED).
Stops execution of the current program and clears the stack. Returns -1 (QUIT).
Makes one step in the currently running program.
There are three special return values corresponding to the stack handling:
0 CONTINUE 1 FINISHED 2 FINISHED_DELAYED
If a command returns CONTINUE, the stack doesn't change. If it returns FINISHED, the following command in the stack is executed. If it returns FINISHED_DELAYED, new commands are put in the stack, but once they're finished, the command behaves as if finished, too.
CONTINUE
FINISHED
FINISHED_DELAYED
To install Karel, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Karel
CPAN shell
perl -MCPAN -e shell install Karel
For more information on module installation, please visit the detailed CPAN module installation guide.