/* * Board.cpp * CIS 250 * David Klick * 2014-03-12 * * This is part of a program that creates a maze. This class represents * the maze itself, which consists of Cell objects. */ #include "Board.h" void Board::getUnvisitedConnectedNeighbors(Cell* c, vector& v) { // ***** ***** // ***** this function must be implemented ***** // ***** ***** } void Board::getConnectedNeighbors(Cell* c, vector& v) { // ***** ***** // ***** this function must be implemented ***** // ***** ***** } void Board::getUnvisitedNeighbors(Cell* c, vector& v) { // ***** ***** // ***** this function must be implemented ***** // ***** ***** } Board::Board(const int r, const int c) { if (r<1 || r>MAX_ROWS) throw "Error: Rows value out of bounds"; if (c<1 || c>MAX_COLS) throw "Error: Columns value out of bounds"; rows = r; cols = c; board = new Cell[rows*cols]; for (int i=0; isetRow(i); cl->setCol(j); if (i == 0) cl->setEdge(NORTH); if (i == rows-1) cl->setEdge(SOUTH); if (j == cols-1) cl->setEdge(EAST); if (j == 0) cl->setEdge(WEST); } } } Cell* Board::getStartCell() { return startCell; } Cell* Board::getEndCell() { return endCell; } void Board::setStartCell(Cell* c) { startCell = c; } void Board::setEndCell(Cell* c) { endCell = c; } Cell* Board::getCell(const int r, const int c) { return board + r * cols + c; } Cell* Board::getAdjacentCell(Cell* cl, direction d) { int r = cl->getRow() + Direction::row(d); int c = cl->getCol() + Direction::col(d); return (board + r*cols + c); } void Board::connect(Cell* cell1, direction d) { cell1->clearWall(d); getAdjacentCell(cell1, d)->clearWall(Direction::opposite(d)); } int Board::getRows() { return rows; } int Board::getCols() { return cols; } void Board::clearVisited() { for (int i=0; isetVisited(false); } void Board::clearValues() { for (int i=0; isetValue(0); } ostream& operator<<(ostream& strm, Board& b) { int r, c; Cell* x; for (c=0; cgetCol() == c) strm << " "; else strm << " _"; } strm << "\n"; for (r=0; rhasWall(WEST)) strm << '|'; else strm << ' '; if (x->hasWall(SOUTH)) strm << '_'; else strm << ' '; } strm << "|\n"; } for (c=0; chasWall(WEST)) strm << '|'; else strm << ' '; if (b.endCell->getCol() == c) strm << ' '; else strm << '_'; } strm << "|\n"; return strm; }