size_t Board::coordsToIndex(const Coords &c) const { if (!inRange(c)) { throw std::out_of_range("Passed coords are outside of board range."); } return dim.getX() * c.getX() + c.getY(); }
bool Coords::operator==(const Coords& c) const { double tol = 0.05; if (std::abs(c.getX() - this->getX()) < tol and std::abs(c.getY() - this->getY()) < tol) { return true; } return false; }
virtual double getArea() { return fabs((c2.getX()-c1.getX())*(c2.getY()-c1.getY())); }
void mapGen(int** checkWall, int** checkVisited, int X, int Y) { int x = 0, y = 1, tolerance = 0; //x and y are the starting coordinates of the path through the maze int sum = 0; Coords temp; temp.setCoords(1, 0); stack<Coords> coordinates; coordinates.push(temp); while (!coordinates.empty()) { //continues the loop until the stack is emptied ////////////////////////////////////////////////// cout << "size of stack: " << coordinates.size() << endl; mapgen << "size of stack: " << coordinates.size() << endl; ///////////////////////////////////////////////// int* possible = checkAvail(coordinates.top(), checkVisited, X, Y, tolerance); //ptr to the array of size 4 that contains the four directions' validity sum = 0; for (int i = 0; i < 4; i++) { sum += possible[i]; //sets sum to the total number of choices } //////////////////////////////////// Coords test = coordinates.top(); int testX = test.getX(); int testY = test.getY(); mapgen << "options: " << sum << " coords: " << testX << " " << testY << endl; /////////////////////////////////////// if (sum == 0) { //executes if there are no choices at the current location (dead end) coordinates.pop(); //pops the top layer off the stack tolerance = 1; //allows checkAvail to evaluate to true even if the location has been visited once before (allows the making of intersections ///////////////////////////////////////// mapgen << "pop" << endl; ///////////////////////////////////////// continue; //back up to beginning of the while loop } tolerance = 0; //for checkAvail on the next run through the loop temp = coordinates.top(); //local variables for the x- and y-coordinates of the current location x = temp.getX(); y = temp.getY(); int Picked = pickDir(possible); ////////////////////////// mapgen << "direction:" << Picked << endl; ///////////////////////// if (x > 0) //updates checkVisited now that we've moved checkVisited[x - 1][y] ++; // if (x < X - 2) // checkVisited[x + 1][y] ++; // if (y > 0) // checkVisited[x][y - 1] ++; // if (y < Y - 2) // checkVisited[x][y + 1] ++; // switch (Picked) //moves us to the next location { // case 0: { //up // y--; // break; // } // case 1: { //left // x--; // break; // } // case 2: { //down // y++; // break; // } // case 3: { //right // x++; // break; // } // } temp.setCoords(x, y); //puts the new location into a Coords object coordinates.push(temp); //adds the new location to the stack checkWall[x][y] = 0; //makes the new location a space checkVisited[x][y] += 2;//sets it to "double visited," so it can never be visited again } }
bool Board::inRange(const Coords &c) const { return c.getX() < dim.getX() && c.getY() < dim.getY(); }
bool Coords::operator<(const Coords& c) const { return this->getX() < c.getX() or(this->getX() == c.getX() and this->getY() < c.getY()); }