Assignment 5, due Thursday February 24 at noon.

You must submit your program electronically via gsubmit on csa.

Under no circumstances will late assignments be accepted.

The code you submit must conform with the programming guidelines. 


Program Description

Write and submit three files: main.cpp, maze.h, and maze.cpp.

In this assignment you will use recursion to find a path through a maze.

Finding a Path Through a Maze

Write a program that uses recursive search with backtracking to solve a maze. This should be a fairly short program but will take some thought, so don't put it off. Think about what the base case(s) are and what the recursive step will be. Remember that with recursion, the idea is to handle one step of the problem and then let the rest be solved in the same way.

Maze Representation

A maze is represented as a 2D array of characters, where characters are interpreted as follows:

' '(blank)   represents empty space
'*'   represents a wall (a cell your solution cannot occupy)
'?'   represents a cell that was considered and rejected by your algorithm
'@' represents a cell on the solution path
'S'  represents the starting position in the maze
'E'  represents the ending position in the maze

When you read the maze data, each cell will contain either a blank or a '*'. Here is an example maze. As you solve the maze, update blank cells to one of the other symbols ('?','@'). Here is an example solution to the example maze.

For this assignment, assume that all mazes have 20 columns and 18 rows.  Your program should read a maze file through standard input.  You should print the resulting solution to standard output in the same format as shown in the example solution.  If there is no solution to the maze, then print an error message to "cerr".

Hint:  Use object-oriented programming.  For instance, you could define a maze class:

const int MAZE_ROWS = 18;
const int MAZE_COLS = 20;

class Maze
{
 public:
  Maze();                            // default constructor
  bool read();                     // reads a maze from standard input
  bool solve(int r, int c);    // recursive solver, that starts at position (r,c) and tries to find 'E' in maze
  void print() const;           // prints a maze to standard output
 private:
  int rows,cols;
  int start_row,start_col;
  char maze[MAZE_ROWS][MAZE_COLS];
};

Grading Criteria

Refer to the grading criteria file: p5.criteria


Academic Honesty and Collaboration

Cooperation is recommended in understanding various concepts and system features. But the actual solution of the assignments, the programming and debugging must be your individual work, except for what you specifically credit to other sources. (Your grade will be based on your own contribution.) For example, copying without attribution any part of someone else's program is plagiarism, even if you modify it and even if the source is a textbook. The University takes acts of cheating and plagiarism very seriously: first time violators are routinely suspended for a semester.