#include #include "maze.h" Maze::Maze(int ncell) { if (ncell < 1) { throw std::invalid_argument("Maze::Maze(): ncell must be >= 1"); } _ncell = ncell; _maze = new cell_t[_ncell]; } Maze::~Maze() { // IMPLEMENT DESTRUCTOR } void Maze::readFile(std::string fileName) { int numCells; int cell, n1, n2, n3, n4; std::ifstream dataFile; dataFile.open(fileName); if (dataFile.is_open()) { dataFile >> numCells; this->reset(numCells); for (int i = 0; i < numCells; i++) { dataFile >> cell >> n1 >> n2 >> n3 >> n4; this->insert(cell_t(cell, n1, n2, n3, n4)); } } } int Maze::getNcell() const { return _ncell; } void Maze::reset(int ncell) { if (ncell < 1) { throw std::invalid_argument("Maze::reset(): ncell must be >= 1"); } if (_maze != nullptr) { delete [] _maze; } _ncell = ncell; _maze = new cell_t[_ncell]; } void Maze::insert(cell_t cell) { if (_maze == nullptr) { throw std::domain_error("Maze::insert(): attempt to insert into uninitialized Maze object"); } if (cell.cellNum < 0 || cell.cellNum >= _ncell) { throw std::invalid_argument("Maze:insert(): invalid cell number"); } _maze[cell.cellNum] = cell; } cell_t Maze::retrieve(int nc) const { if (_maze == nullptr) { throw std::domain_error("Maze::retrieve(): attempt to retrieve from an uninitialized Maze object"); } if (nc < 0 || nc >= _ncell) { throw std::invalid_argument("Maze:retrieve(): invalid cell index"); } return _maze[nc]; } void Maze::dump() const { std::cout << "[*] Dumping the maze cells..." << std::endl; for (int i = 0; i < _ncell; i++) { int nc = _maze[i].cellNum; if (nc != i) { std::cerr << "Warning: maze cell at index " << i <<" has cellNum of " << nc << std::endl; } std::cout << "Cell " << i << " has neighbor cells: "; neighbor_t nbs = _maze[i].neighbors; int n0, n1, n2, n3; if ( nbs[0] >= 0 ) std::cout << nbs[0] << " "; if ( nbs[1] >= 0 ) std::cout << nbs[1] << " "; if ( nbs[2] >= 0 ) std::cout << nbs[2] << " "; if ( nbs[3] >= 0 ) std::cout << nbs[3] << " "; std::cout << std::endl; } } std::vector Maze::solve() const { // IMPLEMENT THE SOLVE METHOD } Maze::SolveStack::SolveStack() { _stack = nullptr; } Maze::SolveStack::~SolveStack() { // IMPLEMENT DESTRUCTOR } bool Maze::SolveStack::empty() const { return _stack == nullptr; } void Maze::SolveStack::push(src_dest_t src_dest) { // IMPLEMENT PUSH METHOD } src_dest_t Maze::SolveStack::pop() { // IMPLEMENT POP METHOD } src_dest_t Maze::SolveStack::read() const { // IMPLEMENT READ METHOD }