CS-182 Lab 6: Applying Selection Statements

Dr. Mark J. Sebern


CS-182 Main Page Schedule General lab information

Overview

The purpose of this lab is to apply selection statements to complete an application.

Activities

In this lab, you will:

Problem statement

You have been asked to design and implement a computer program to navigate through a maze. You have been given an application that is complete except for the module that controls the maze navigation. Your job is to implement that module. Initially, the maze might look like this:

The red circle represents "your" position in the maze as you attempt to reach the target (the blue square). You may travel only on the white maze cells; the green cells are off limits.

[Note: the colors may not be distinguishable on black-and-white printouts of this page. Run the application or view this web page on-line to see the colors.]

The application program calls your module to determine what move to make next; the possible moves are:

If you navigate the maze correctly, the end result may look something like this:

The yellow squares indicate the path that you took to reach the target. Note that the final path may be different, depending on the method you use to navigate. The actual maze is generated "pseudo-randomly" and depends on the "maze number" value and the behavior of the random-number generator on your computer.

Your module must provide the following:

The interfaces to your functions are as follows:

void MazeReset ();
// This function is called when the maze is initialized.

bool DoMove (MazeMove& move);
// Make the next move, based on the state of the maze.
// Arguments:
//    move - MazeMove object for move
//           This object's member functions may be used to check for
//           valid moves.
// Returns:
//    false, if no move should be made (maze complete)
//    true, if a move should be made
//      If true, the "move" object describes the desired move
//      (as set by MazeMove member functions).

You can find these interfaces in the file maze2.h and sample definitions in the file maze2.cpp. Your job is to replace the body of the module to implement your navigation algorithm.

The argument to the DoMove function is an object that communicates your current position in the maze and "carries back" instructions on the move you choose to make. The MazeMove object has the following member functions:

class MazeMove
{
public:
  enum MoveType { move_none, move_right, move_up, move_down };
  // This enumerated type is used to specify one of the possible
  // moves in the maze: no move, right, up, or down.

  bool IsOnTarget () const;
  // Checks to see if the current maze cell is the target cell.
  // Returns: true, if the current cell is the target cell;
  //          false, otherwise.

  bool CanMove (MoveType move) const;
  // Tests to see if a specified move is legal from the current
  // maze cell.
  // Arguments:
  //     move - proposed move type
  // Returns: true if move is legal; false otherwise.
	
  void MakeMove (MoveType move);
  // Requests that a particular type of move be made from the
  // current cell.
  // The move is requested whether it is legal or not.
  // If this function is called more than once for a given move,
  // the last specified move type is used.
  // Arguments:
  //     move - requested move type
}; 

Detailed instructions

If you have difficulties with any part of the lab, consult the instructor for assistance. The basic sequence is:

  1. Download the file containing the source code and other files necessary to build the application.

    If you are using an older compiler on another system, you may download one of the following older versions of this lab:

  2. Unpack the ZIP archive using WizUnZip on the warp network or a similar tool. With some tools (e.g., PKUNZIP), you may need to specify the "-d" option to create subdirectories for the Microsoft version of the files.
  3. Open the supplied project file (part of the ZIP archive) and build the application. You may need to adjust the project directory paths if you are running on your own computer. Run the application; the example code in maze2.cpp will implement a incorrect version of the maze navigation.
  4. Design a navigation algorithm.
  5. Modify the body of maze2.cpp so that it implements your algorithm. Do not modify any other source files.
  6. Test the program.
  7. Extra credit: If the basic navigation is too simple for you, modify your program so that it visits every open maze cell before terminating. In other words, all initially white (open) cells should be yellow (visited) when your navigation terminates. Note that you must still end up at the target cell.
  8. Submit the lab report (details below).

Lab report

The lab report should consist of the following:

You may submit this report in hard-copy form, or email it to the instructor. If you choose email, it may be convenient to put the textual portion of the report directly in the message, and to attach the source file. Be sure to keep copies of all your files, in case something gets lost; it may be wise to keep a diskette backup as well.

The lab report is due by the beginning of the following lab period, though you are encouraged to submit it sooner if you can. Your grade will depend on quality of design and clarity of the code and documentation. If you have any questions, consult the instructor.

In addition to the lab report, please demonstrate your final program to the instructor. This may be done during the lab period, or at another mutually agreed time. The demonstration should be done no later than the first hour of the following lab period.

Acknowledgment

The animation program is based on an idea embodied in a program developed by Richard Rasala and others at Northeastern University.


This page was last updated on September 02, 1997; send comments to Mark Sebern.