bool Maze::isGoal(point loc) // DEPRECIATED - kept around for backwards compatibility { if(!validRoom(loc)) exitWithPopup("You passed an invalid cell id to is_goal",0); return dynamic_cast<GoalCell*>(getCell(loc.y, loc.x)); }
/* * Returns the room in the given direction, taking into account walls and * the edge of the maze. If a room is successfully returned it will be marked * so the solver knows it's been looked at */ point Maze::roomAt(point curr,Direction dir){ point nowhere(-1,-1); if (!validRoom(curr)) exitWithPopup("You passed an invalid cell id to get_neighbors",nowhere); if(getCell(curr.y, curr.x)->hasWall(dir)){ return nowhere; }else{ point end=curr; switch(dir){ case NORTH : end.y--; break; case SOUTH : end.y++; break; case EAST : end.x++; break; case WEST : end.x--; break; default : return nowhere; } if(validRoom(end)) return end; else return nowhere; } }
int addRoom(lvl *level, int showGen, room *rooms, int tries){ int x = rb(1, MAX_W-RM_MAXX-2); int y = rb(1, MAX_H-RM_MAXY-2); int w = rb(3, RM_MAXX); int h = rb(3, RM_MAXY); if (validRoom(level, h+2, w+2, x-2, y-2, 1, showGen)){ rooms->setPoints(x,y,x+w,y+h); recurClear(level, h, w, x, y, 1, showGen); return (1); } else if(tries<=30){ return (addRoom(level, showGen, rooms, ++tries)); } return 0; }
int Maze::undoMove(point loc) { if (!validRoom(loc)) return 0; // TODO: possibly not just empty, but last maze status before moveCurrent() // cerr << "currCell: " << currCell.y << ", " << currCell.x << endl; // cerr << "undo: " << (currCell.x==loc.x&&currCell.y==loc.y); getCurrentCell()->setMazeStatus(getCurrentCell()->getOldMazeStatus()); getCell(loc.y, loc.x)->setMazeStatus(CURRENT); // grid[currCell.y][currCell.x].setMazeStatus(EMPTY); // grid[loc.y][loc.x].setMazeStatus(CURRENT); currCell = loc; --nodesVisited; // cerr << "End-currCell: " << currCell.x << ", " << currCell.y << endl; onNodesVisitedChanged(); // TODO: update m_noVisited counter return 1; }
/* * moves the little guy to the right point */ int Maze::moveCurrent(point loc) { if (!validRoom(loc)) exitWithPopup("You passed an invalid cell id to draw_arrow",0); //cerr << "moveCurrent: " << currCell.y << ", " << currCell.x; // cerr << ", (" << getCurrentCell() << ", " << getCell(loc.y, loc.x) << ")\n"; getCurrentCell()->setMazeStatus(SEARCHED); // cerr << "moveCurrent: " << getCurrentCell()->getMazeStatus() << endl; // m_grid[currCell.y][currCell.x].setMazeStatus(SEARCHED); getCell(loc.y, loc.x)->setMazeStatus(CURRENT); // m_grid[loc.y][loc.x].setMazeStatus(CURRENT); currCell = loc; ++nodesVisited; onNodesVisitedChanged(); // cerr << ";moveCurrent\n"; // TODO: update m_noVisited counter return 1; }
/* * Have we been here before? returns essentially if the * specified square is now purple */ int Maze::isSearched(point loc){ if(!validRoom(loc)) exitWithPopup("You passed an invalid cell id to is_searched",0); return (getCell(loc.y, loc.x)->getMazeStatus() == SEARCHED); }