Question
#ifndef MAZE_H #define MAZE_H #include #include struct Coordinate // 2D point consisting of x and y coordinates { double x, y; Coordinate(double px, double py)
#ifndef MAZE_H
#define MAZE_H
#include
#include
struct Coordinate // 2D point consisting of x and y coordinates
{
double x, y;
Coordinate(double px, double py) : x(px), y(py) {} // Constructor with initializer list
};
class Maze // Represents Maze class' data and function members
{
public:
Maze(std::ifstream&); // Constructor: takes file object and reads maze map from file
void Print(); // Displays the maze and its state
Coordinate GetStartPt(); // Returns a randomly chosen maze starting point - use coords member
void FindExit(int, int, bool&); // Recursive function that attempts to find the exit
private:
char maze[10][10]; // 2D array that holds maze - outer columns and rows not traversable
int maxRows; // Maximum number of rows - excludes outer walls
int maxCols; // Maximum number of columns - excludes outer walls
std::vector
};
#endif
Objectives: 1) Use recursion; 2) Understand and apply backtracking; 3) Use STL container; Project description: Write a C++ program that, given a starting point, finds its way out of a maze. The maze's map will be read from a file at the start of the program. Your code must work for all legal mazes.. The maze is a rectangular grid represented as a 2D array, and the exit (if there is one) should be placed on an outer row or column of the play area. The program should run until the exit to the maze is found or until it is determined that there is no exit (after exploring all traversable cells) Exploration of the maze is done by recursively invoking a function and marking the cells visited with a special character (an electronic bread crumb to keep from revisiting explored cells). The legal moves are to cells adjacent but not diagonal to the cell currently occupied. Candidates for the next move are cells that are traversable and have not been previously visited. If the specially marked exit cell is encountered the game should exit with a message that the exit was found Otherwise, after exploring the whole maze, a message is output stating that there is no exit. At left is an instance of a maze. Note the attributes of a legal maze X X X marks non-traversable cells-The cells in red are not part of the maze map read from the file. They mark the boundary of the maze, and must be represented as not traversable. The actual play area has 2 fewer columns and 2 fewer rows than the 10x10 maze map array (i.e. you will read a maximum 8x8 play area from the file). Blue squares are walls * (yellow) shows traversable cells that have been previously visited and should not be revisited when locating the exit X 0 0 0 0 X X X 0 X O X O O O O O X X X X OX OX OXOO cells (green) are traversable cells that have not been visited. All traversable cells must be reachable from any other traversable cell E marks the exit (outlined gray cell) - If it exists, It must be placed on one of the outer rows or columns of the play area. The exit must be reachable from any traversable cells in the maze (it can't be contained within walls) . Requirements 1. Your program must be split into 3 files. There will be a class (with separate interface and implementation files), and a driver file. The requirements for these are specified below a) The Maze class - This class represents a maze Files must be named maze.h and maze.cpp Class must be named Maze The interface (header file) is provided . . Objectives: 1) Use recursion; 2) Understand and apply backtracking; 3) Use STL container; Project description: Write a C++ program that, given a starting point, finds its way out of a maze. The maze's map will be read from a file at the start of the program. Your code must work for all legal mazes.. The maze is a rectangular grid represented as a 2D array, and the exit (if there is one) should be placed on an outer row or column of the play area. The program should run until the exit to the maze is found or until it is determined that there is no exit (after exploring all traversable cells) Exploration of the maze is done by recursively invoking a function and marking the cells visited with a special character (an electronic bread crumb to keep from revisiting explored cells). The legal moves are to cells adjacent but not diagonal to the cell currently occupied. Candidates for the next move are cells that are traversable and have not been previously visited. If the specially marked exit cell is encountered the game should exit with a message that the exit was found Otherwise, after exploring the whole maze, a message is output stating that there is no exit. At left is an instance of a maze. Note the attributes of a legal maze X X X marks non-traversable cells-The cells in red are not part of the maze map read from the file. They mark the boundary of the maze, and must be represented as not traversable. The actual play area has 2 fewer columns and 2 fewer rows than the 10x10 maze map array (i.e. you will read a maximum 8x8 play area from the file). Blue squares are walls * (yellow) shows traversable cells that have been previously visited and should not be revisited when locating the exit X 0 0 0 0 X X X 0 X O X O O O O O X X X X OX OX OXOO cells (green) are traversable cells that have not been visited. All traversable cells must be reachable from any other traversable cell E marks the exit (outlined gray cell) - If it exists, It must be placed on one of the outer rows or columns of the play area. The exit must be reachable from any traversable cells in the maze (it can't be contained within walls) . Requirements 1. Your program must be split into 3 files. There will be a class (with separate interface and implementation files), and a driver file. The requirements for these are specified below a) The Maze class - This class represents a maze Files must be named maze.h and maze.cpp Class must be named Maze The interface (header file) is provided
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started