import kareltherobot.*; public class MazeWalker extends Robot { public MazeWalker(int street, int avenue, Direction direction, int beepers) { super(street, avenue, direction, beepers); } /** * This 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() ) followRightWall(); } /** * This will move the Robot according to the diagram * mentioned. */ public void followRightWall() { if(! frontIsClear()) { turnLeft(); } else { move(); turnRight(); if( ! frontIsClear() ) turnLeft(); else { move(); turnRight(); if (! frontIsClear() ) turnLeft(); else move(); } } } public void turnRight() { for (int i=0; i<3; i++) turnLeft(); } }