Skip to main content.

Thursday, February 2, 2006
Due: Wednesday, February 8, 2006 - 10:00PM

Today you will work on a problem similar to that described on pages 513-514 in the book (Programming Project 13.1).

Lab Exercises

1.

In your Eclipse workspace, start a new project called "lab04". Download this Java archive (JAR) file: lab04maze.jar onto the desktop of your computer. From the File menu in Eclipse, choose "Import", select "Archive file", find the lab04maze.jar file that you downloaded, and import it into the "lab04" project folder in your Eclipse workspace. Delete the file from the desktop when you are done.

You should get a bunch of files imported into your lab04 project. These are to get you started on this week's homework exercise. For the rest of this lab you will become familiar with the files and start to work on the homework.

2.

First, look over the "griddoc.txt" file. It gives an overview of the classes that I have provided to you. Other than the code having to do with exceptions and with file input/output, you should be able to understand most of the code in these classes - it involves GUI layout, event handling, animation, arrays, etc.

The classes I have provided you can read in maze information from a file. I have provided you several predefined mazes of different sizes. Do you see the maze files? Look over them and see if you understand their format.

3.

To become familiar with the operation of these classes, you are to write a RandomRobot in lab today. This "robot" should traverse the maze by randomly wandering in different directions, beginning at the start cell, until it reaches the end cell.

First, create a new class called "RandomRobot" that extends "MazeSolver". The MazeSolver class provides a skeleton for your maze solving algorithms. It provides you with all the infrastructure needed for analyzing and displaying a maze object.

In the RandomRobot class, create a method with the header: "protected void findPath()". You can leave this method empty for now. This is the method you need to fill in with your maze search algorithm.

In the RandomRobot class also, add the following main method:

   public static void main( String[] args ) {
      RandomRobot rr = new RandomRobot();
      rr.setVisible(true);
   }

Now try running the RandomRobot class. It should ask you to open a maze file. Browse to one of the ones in your Eclipse workspace/project folder and open it. It will then display the maze on the screen with a button to start the search. Right now it doesn't do anything. You need to fill in the findPath() method to get it to find a path from start to finish.

Try to figure out how to write the RandomRobot code. Some methods of the maze class that may be useful are the getStart(), getEnd(), getMark(), and setMark() methods. The repaintAndPause() method in the MazeSolver class may also be useful for seeing the animation as your robot searches the maze.

If you need help figuring out what to do, ask me.

Homework Exercises

[80 points] Complete Programming Project 13.1 on page 513. You only need to implement one other robot strategy besides the random one. You may use one of the strategies that the book talks about, or use a strategy of your own devising that will produce better (shorter and more direct) paths than the RandomRobot. For these more complicated robots, you may need to use auxiliary data structures (i.e. extra arrays or array lists) in your robot subclass to keep track of previous positions, etc.

Along with your source code you should submit a readme.txt (plain text) file describing your robot's algorithm for searching the maze.

Note: All source code that you produce must conform to the following style guide, adapted from the textbook's Appendix A: Java Programming Style Guide. Be sure to include appropriate comments in your code!!!

Your completed source code files should be turned into the proper submit folder (submit04) by the deadline.