Question: Please complete file Maze.cpp, and main.cpp The Header file is provided below: #ifndef MAZE_H #define MAZE_H #include #include struct Coordinate // 2D point consisting of
Please complete file Maze.cpp, and main.cpp
The Header file is provided below:
#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 coords; // holds initially traversable locations on the map }; #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 determines 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 reprocessing explored cells). The legal moves are to cells adjacent but not diagonal to the cell currently occupied. The maze should be solved through recursive calls and backtracking, and not by looking ahead. 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. X X At left is an instance of a maze. Note the attributes of a legal maze X marks non-traversable cells-The cells in red are not part of the maze o map read from the file, but must be constructed around it. They mark the boundary of the maze, and are represented as not traversable. The maze will always have two more columns and two more rows than the play area read from the file (the maze at left has the maximum 8x8 play area, and fills the 10 x 10 array). Blue squares are walls o o O o O X*(yellow) shows traversable cells that have been previously visited and should not be reprocessed when locating the exit. O 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) xo ox o o ox ox 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 determines 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 reprocessing explored cells). The legal moves are to cells adjacent but not diagonal to the cell currently occupied. The maze should be solved through recursive calls and backtracking, and not by looking ahead. 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. X X At left is an instance of a maze. Note the attributes of a legal maze X marks non-traversable cells-The cells in red are not part of the maze o map read from the file, but must be constructed around it. They mark the boundary of the maze, and are represented as not traversable. The maze will always have two more columns and two more rows than the play area read from the file (the maze at left has the maximum 8x8 play area, and fills the 10 x 10 array). Blue squares are walls o o O o O X*(yellow) shows traversable cells that have been previously visited and should not be reprocessed when locating the exit. O 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) xo ox o o ox ox
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
