Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void mazegenerator::Generate(int rowCount, int colCount) //Generates 'maze' using vectors.
- {
- // Resize origin and inner vectors to desired sizes.
- maze.resize(rowCount);
- for (int i = 0; i < rowCount; i++)
- {
- maze[i].resize(colCount);
- }
- int row = 1;
- int col = 1;
- Tile& tile = maze[row][col];
- // Set default values for Tile attributes iterating through every 'Tile'
- for (int r = 0; r < maze.size(); r++)
- {
- for (int c = 0; c < maze[0].size(); c++)
- {
- tile.row = r;
- tile.col = c;
- tile.visited = false;
- tile.blocked = true;
- }
- }
- tile.blocked = false;
- tile.visited= false;
- /*for (int r = 0; r < getRowCount(); r++) // Iterate through rows
- {
- for (int c = 0; c < getColCount(); c++) // Iterate through cols
- {
- Tile& tile = maze[r][c]; // tile = maze position r, c E.g. 0, 1
- for (int i = 0; i < neighbours.size(); i++) // i = 0; If i is less than size of neighbours then i++
- {
- cout << "Neighbour " << i << ": row:" << neighbours[i].row << " col: " << neighbours[i].col << endl;
- }
- }
- }*/
- /*cout << "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB" << endl;
- for (int r = 0; r < getRowCount(); r++)\
- {
- cout << row << "," << col << endl;
- for (int c = 0; c < getColCount(); c++)
- {
- cout << "\tRow: " << r << " Col: " << c << endl;
- }
- cout << "\n";
- if(row != getRowCount())
- row = row + 1;
- if (col != getColCount())
- col = col + 1;
- }
- cout << "\n";*/
- //cout << "Number of Neighbours for [" << row << "," << col << "]: " << *neighbours.size() << "\n" << endl;
- //cout << "Neighbour\tRow\tCol\tVisited" << endl;
- while (!maze.empty())
- {
- //Get current tile
- Tile thisTile = maze.front();
- //Get unvisited neighbours
- vector <Tile*> neighbours = getUnvisitedNeighbours(&tile, row, col);
- if (!neighbours.empty())
- {
- Tile nexttile = *neighbours[rand() % neighbours.size()];
- // Get wall between tiles
- int midRow = tile.row + (nexttile.row = tile.row) / 2;
- int midCol = tile.col + (nexttile.col = tile.col) / 2;
- Tile tileWall = maze[midRow][midCol];
- // Mark neighbour and wall cells as unblocked
- nexttile.blocked = false;
- tileWall.blocked = false;
- //Add neighbour to top of stack and mark visited
- maze.push_back(nexttile);
- nexttile.visited = true;
- }
- else
- {
- maze.pop_back();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement