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.
First, create an Eclipse project by following these steps:
Next, try running the application:
The user interface elements are:
After a successful completion of a maze navigation run, you should see something like this:
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]
Upon completion, demonstrate your program to your instructor. Your instructor may ask you to use specified maze numbers in this demonstration.
Record the time you spent on this assignment in FAST, and submit your assignment as specified by your instructor.se1010lab4.zip