rendered paste body#include "maze.h"
void Maze::pushNextCell(int row, int col){
if (store[row][col+1] == passage || store[row][col+1] == exitMarker){
mazeStack.push(Cell(row,col+1));
mazeStack2.push(Cell(row,col+1));
return;
}
if (store[row][col-1] == passage || store[row][col-1] == exitMarker){
mazeStack.push(Cell(row,col-1));
mazeStack2.push(Cell(row,col-1));
return;
}
if (store[row+1][col] == passage || store[row+1][col] == exitMarker){
mazeStack.push(Cell(row+1,col));
mazeStack2.push(Cell(row+1,col));
return;
}
if (store[row-1][col] == passage || store[row-1][col] == exitMarker){
mazeStack.push(Cell(row-1,col));
mazeStack2.push(Cell(row-1,col));
return;
}
mazeStack.push(Cell(-1,-1));
}
void Maze::pushUnvisited(int row, int col) {
if (store[row][col] == passage || store[row][col] == exitMarker) {
mazeStack.push(Cell(row,col));
}
}
void Maze::exitMaze() {
Cell backtrack(-1,-1);
int row, col;
currentCell = entryCell;
while (!(currentCell == exitCell)) {
row = currentCell.row;
col = currentCell.col;
cout << *this; // print a snapshot;
if (!(currentCell == entryCell))
store[row][col] = visited;
pushNextCell(row,col);
if (mazeStack.empty()) {
cout << *this;
cout << "Failure\n";
return;
}
else currentCell = mazeStack.pop();
if(currentCell==backtrack)
currentCell= mazeStack2.pop();
}
cout << *this;
while(!mazeStack2.empty()){
Cell tmp = mazeStack2.pop();
cout << '[' << tmp.row << ',' << tmp.col << ']' << ' ';
}
cout << '\n';
cout << "Success\n";
}