This is not a current assignment. If you are currently enrolled in SE1010, do not do this assignment expecting to receive credit for it.

Lab 4

Background

In this assignment, you will use selection (e.g., if or switch) statements to control navigation through a maze. The maze application consists of an interface framework (provided for you) and a navigation class that you will have to complete.

Setup Procedure

First, create an Eclipse project by following these steps:

  1. Download the file se1010lab4.zip and save it in a convenient location on your computer. (Depending on your browser, you may need to do a right click to save the file.) DO NOT save the file inside your Eclipse workspace.
  2. From the File menu, select New⇒Project.
  3. In the New Project dialog box, select Java Project and click on Next.
  4. In the Project Name field, enter “Lab4” or a project name of your choice.
  5. Make sure that the correct options are selected (see creatingaproject).
  6. Click on Finish to create the project.
  7. Right click on the project name (e.g., “Lab4”) in the Package Explorer, and select Import… from the pop-up menu.
  8. In the Import dialog box, select General⇒Archive File and then click on Next.
  9. In the From archive file: field, browse to the se1010lab4.zip file you previously downloaded and then click on Finish.
  10. In the Package Explorer, right-click on the maze.jar file that should now be listed in your project. Select Build Path⇒Add to Build Path.

Next, try running the application:

  • Right-click on the maze.jar file in the Package Explorer, and select Run As⇒Java Application from the pop-up menu.
  • You should now see the maze application:

The user interface elements are:

  • Maze - Array of cells. The red circle marks the current position and the blue square indicates the target cell. Green cells are forbidden areas; moving into one of them is illegal. Open cells are initially white and change to yellow once they have been visited. If you see a black cell, it means a move has been made into a forbidden (originally green) cell.
  • Maze number field - A numeric value that selects a particular maze pattern.
  • Moves made field - Displays the number of moves that have been made so far.
  • Reset button - Restores the maze to the initial configuration corresponding to the maze number.
  • Step button - Causes one navigation move to be made.
  • Run button - Starts an automatically timed sequence of navigation moves.
  • Stop button - Stops the automatic navigation sequence.
  • Exit button - Exit from the maze application.

After a successful completion of a maze navigation run, you should see something like this:

Assignment

Your job is to edit the MazeNavigator.java file in your project, so that it selects the correct moves to navigate the maze. The makeMove method is called by the maze application framework. The return value from this method tells the framework what move to make. The moveInfo argument is a reference to an object that provides information about the current state of the maze; you should use this information to decide what move to make.

The Javadoc for some of the maze application classes is located at [http://people.msoe.edu/~sebern/courses/se1010/mazedoc/]. Ask your instructor if you have any questions about how these classes work.

A really simple (and incorrect) implementation of the makeMove method might look like this:

public static MoveType makeMove (MazeMoveInfo moveInfo) {
    MoveType move = MoveType.MOVE_RIGHT;
    return move;
}

This version ignores the information provided by the moveInfo argument, and always moves to the right at every opportunity. In general, this won't work. (For one thing, it will never stop, even if it does stumble onto the target cell!)

A slightly improved version might be:

public static MoveType makeMove (MazeMoveInfo moveInfo) {
    MoveType move = MoveType.MOVE_NONE;

    if (moveInfo.isOnTarget()) {
        move = MoveType.MOVE_NONE;
    } else if (moveInfo.canMove(MoveType.MOVE_RIGHT)) {
        move = MoveType.MOVE_RIGHT;
    } else {
        move = MoveType.MOVE_UP;
    }
    return move;
}

Here, the makeMove method examines the moveInfo argument to see if the current position has reached the target location. If not, it asks whether it is OK to move right, and makes that move if it is. Otherwise, it always moves up. Obviously, this probably won't work right for most mazes either.

It's your job to finish the MazeNavigator class so it works correctly. Notice that there is an init method that gets called automatically at the very beginning of a navigation run (before the first move). You may need to add some code to this method, or to define static (class) variables, depending on the navigation method you choose to implement.

Test your program using different maze patterns (maze numbers) to make sure that it handles a variety of cases correctly. The GUI display should help you to see whether your navigation strategy is working correctly and to help you understand any problems you may encounter. Be sure to ask your instructor for assistance if you get stuck.

If you would like an additional challenge, try modifying your navigation method so that every open cell in the maze is visited, before ending on the target cell. In this case, every initially white cell would be colored yellow at the end of the maze traversal. Talk to your instructor before adding this capability, and be sure to save a copy of your solution to the basic assignment (just in case you run into problems).

NOTE: If you want try the additional challenge, there was a defect in an earlier version of the maze application framework that caused the maze traversal to end prematurely, the first time the target cell was reached. This has been fixed in V1.1 (version number at the bottom of the window). If you have V1.0, you'll have to re-download the current version of the se1010lab4.zip file; make sure your browser doesn't give you an older cached copy. [Sorry for any inconvenience; it was my mistake. – Dr. Sebern]

Demonstration

Upon completion, demonstrate your program to your instructor. Your instructor may ask you to use specified maze numbers in this demonstration.

Deliverables

Record the time you spent on this assignment in FAST, and submit your assignment as specified by your instructor.se1010lab4.zip

se1010labs/lab4.txt · Last modified: 2009/06/03 11:22 (external edit)
 

This website is not owned or managed by the Milwaukee School of Engineering.

© 2003-2010 Dr. Christopher C. Taylor, et. al. • Office: L-343 • Phone: 277-7339 • npǝ˙ǝosɯ@ɹolʎɐʇ • -> RSS <-