Lab 8 - Stacks and Mazes

 

Due Tuesday November 17, 1998

The purpose of this lab is to spend some time with stacks, one of the most important data structures in computer science.  In addition, we will see some of the basic graphics routines available in C++.  For this purpose I have created a new way of creating projects, which will automatically give you access to a handy library of graphics routines.  When you want to use these routines, instead of creating a project with the Standard C++ console, you can now create one with using C++ Graphics Console PPC.
 

Assignment

In our source folder there are three relevant files for this assignment.  maze.cpp, maze.h and Maze1.  Together these files demonstrate some of the graphics routines.  One of the ways in which they are demonstrated is by having a rat randomly wander through the maze.  Your assignment is to use stacks to change the rat's random walk through the maze into a search.  In addition, you are to animate the stack, displaying its contents throughout the course of the search.

The maze is modeled as an nXm matrix with the start square at 1,1 and the finish at 10,11.  1's in the array represent walls, while 0's represent corridors.  The purpose of the stack is to keep track of where the rat has been.  Each time the rat moves into a new square, that location is pushed onto the stack.  In addition, the maze is updated so the rat will not try to return to the square again.  The rat continues to make legal moves until it is done, or until it gets to a place where it cannot move any further.  If it is blocked, it begins to pop moves off the stack (and the maze is updated appropriately to show that the square is available again) until it gets to a location from which it can make another choice.  The tricky part of the algorithm is managing situations where the rat is trapped and has to backtrack.  The key is determining which moves the rat has attempted from which locations.

For debugging and display purposes it will be worthwhile to slow your program down.  The simplest way is by using keyboard input.  Other ways may also prove useful.  When you are done, I would like to see a smoothly running program which shows the paths tried by the rat in an easy to watch format.  In addition, as already noted, your program should animate the contents of the stack as it peforms pushes and pops.
 

What to hand in

As usual, put the final version of your program and related files into the drop box, with appropriate names used.  As always, hard copy is also essential.  In addition to modifying the provided program, you should also include a file called stack.h in which you define your stack data structure and all of its related functions.