User Tools

Site Tools


This is an old revision of the document!

Write an instruction followWallRight for the MazeWalker class, assuming that whenever a robot executes this instruction there is a wall directly to the right. It should be able to handle these four possible situations:



Here are four of the different position changes that the robot must be able to make. This instruction is the cornerstone for the program that directs a robot to escape from a maze. It isn't the most efficient algorithm, and it won't work on mazes that have islands (Can you imagine why?). Do you think following the left walls would be better?

import kareltherobot.*;
public class MazeWalker extends Robot
	public MazeWalker(int street, int avenue, Direction direction, int beepers) {
		super(street, avenue, direction, beepers);
     * This is an algorithm to run a maze. It isn't the fastest method,
     * and won't work if the maze has any islands (Can you imagine why?)
     * Would it be better to follow the leftWalls?
	public void escapeMaze() {
		while (! nextToABeeper() )
     * This will move the Robot according to the diagram
     * mentioned.
	public void followRightWall() 
	public void turnRight() {
		for (int i=0; i<3; i++)

First use the MazeWalkerTester to see if your code deals with the four situations correctly.

Once the tester shows that the four cases are handled correctly, here is a maze runner class with its own maze:

mazewalker.1567136702.txt.gz · Last modified: 2019/08/29 23:45 by frchris