CS320      Project 1 - 2D Maze

A maze can be looked at as an array of m x n square cells, where m is the number of rows and n is the number of columns in the maze. Each cell has the property that one to three of its sides (or walls) is present. If two walls are present there is a path into the cell and a path leaving the cell. If three walls are present, the cell is a dead end. It is also possible to have a cell with a single wall. (Note: a maze can be represented by a graph in which each node represents a cell and each branch a connection between cells, i.e., the absence of a wall between adjacent cells.)

You are to use OpenGL to construct and display a maze where m and n are command line inputs to the program. The particular type of maze you are to construct is one in which every cell is connected to every other cell and there is exactly one simple path between any pair of cells.

One method to construct such a maze is to start with an array of cells, each of which has all four walls present. We then remove various walls to construct the desired maze. Consider the following algorithm. Initially all cells are said to be unvisited. We start by selecting (visiting) a random cell. We connect this cell to one of its neighbors by randomly visiting one of its unvisited neighbors recursively. We remove the wall between the two cells to connect them. If any of the other three neighbors has not been visited, we recursively visit them. If we reach a dead end (a cell all of whose neighbors has been visited), we return. When all cells are visited, the first visit call returns and we have a maze. (Note that the algorithm requires a data structure to keep track of which cells have been visited and which have not been visited. ) We can then remove two pieces of the outside wall to create an entrance and an exit to the maze. You are also to show a path in another color from between the entrance and exit. This is another simple, recursive algorithm.

The graphics part of this project is very simple: The overall size of the maze should be made slightly smaller than the size of the rendering window. Divide the dimensions of the maze by the number of rows and columns to determine the size of a cell. Begin drawing lines. You can do most of the work before using any graphics at all.

Here are some suggestions and pseudo-code to assist you:


 

visit() Pseudo-code

visit(current cell)
{
   mark current cell visited;

   Randomly arrange the four compass directions

   for each of the four randomly arranged compass directions
      if new cell exists and is unvisited
      {
         remove appropriate wall;
         visit(new cell);
      }
}
path() Pseudo-code
path(current cell, target cell)
{
   mark current cell visited;

   if current cell == target cell
      return true;

   for each of the four neighbor cells
      if new cell exists and is unvisited
         if (path(new cell, target cell))
         {
            draw segment from current cell to new cell;
            return true;
         }

   return false;
}

The following will be taken into consideration in evaluating your work:

  1. The design and generality of your solution.
  2. Completeness of testing. (Of course, you need to provide evidence of testing --- you will lose points for not documenting this.)
  3. The readability of your code.
     

Submit your project in a single ZIP archive.