#include <RecursiveDivision.h>
Public Member Functions | |
bool ** | initMaze (int width, int height) |
int | generateMaze (std::istream &is) |
void | divideField (bool **field, int left, int right, int top, int bottom) |
void | divideVertical (bool **field, int left, int right, int top, int bottom) |
void | divideHorizontal (bool **field, int left, int right, int top, int bottom) |
void | makeMazeOpening (bool **field, int rows, int cols) |
void | drawMaze (bool **field, std::ostream &output) |
int | generateRandomInt (int lower, int upper) |
bool | generateRandomBoolean () |
Public Attributes | |
LabGraph * | labPrinter |
bool | debugMode = false |
Class with recursive division algorithm.
Creates a NxM empty maze field surrounded by a wall. Each time this field will be separated by a wall with a passage into two smaller fields. These new small field will be separated in another two smaller fields and so on.
After each field have the minimum size of 2x2 a start opening and a end opening will be calculated.
void RecursiveDivision::divideField | ( | bool ** | field, |
int | left, | ||
int | right, | ||
int | top, | ||
int | bottom | ||
) |
Arbitrator method for the recursive division.
It consumes the maze and the current coordinates of the field. These coordinates are the four directions. This method choose by the width and height if the field will be divided and in which direction.
field | The complete maze field. |
left | The column index of the left column. |
right | The column index of the right column. |
top | The row index of the top row. |
bottom | The row index of the bottom row. |
void RecursiveDivision::divideHorizontal | ( | bool ** | field, |
int | left, | ||
int | right, | ||
int | top, | ||
int | bottom | ||
) |
Divide the sub-field with a horizontal wall.
It choose a random number for the column index where the wall will be placed. After that the wall will be added and a random column index is calculated to open the passage. After that, this method calls the generateMaze() Method again with the new two, smaller fields.
field | The complete maze field. |
left | The column index of the left column. |
right | The column index of the right column. |
top | The row index of the top row. |
bottom | The row index of the bottom row. |
void RecursiveDivision::divideVertical | ( | bool ** | field, |
int | left, | ||
int | right, | ||
int | top, | ||
int | bottom | ||
) |
Divide the sub-field with a vertical wall.
It choose a random number for the row index where the wall will be placed. After that the wall will be added and a random row index is calculated to open the passage. After that, this method calls the generateMaze() Method again with the new two, smaller fields.
field | The complete maze field. |
left | The column index of the left column. |
right | The column index of the right column. |
top | The row index of the top row. |
bottom | The row index of the bottom row. |
void RecursiveDivision::drawMaze | ( | bool ** | field, |
std::ostream & | output | ||
) |
Consumes the maze field and draw it at the console output.
field | Maze field. |
output | output stream (only for testing purpose). |
int RecursiveDivision::generateMaze | ( | std::istream & | is | ) |
Start method of this class with console.
It ask for cols and rows of the maze. Theses are the relative sizes of the maze, because of the walls. A maze with 2 cols have an absolute width of 6. Two for the walls on the left and on the right, two for the given col amount and 2 for walls between them.
is | input-stream for reading input params. |
Enable Debug mode for maze printing:
bool RecursiveDivision::generateRandomBoolean | ( | ) |
Generate a random boolean value.
int RecursiveDivision::generateRandomInt | ( | int | lower, |
int | upper | ||
) |
Generate a random integer value between the lower and the upper boundary.
lower | Lower bound. |
upper | Upper bound. |
bool ** RecursiveDivision::initMaze | ( | int | width, |
int | height | ||
) |
Method which generate the empty maze field.
Field is surrounded by a wall.
The generated field is a 2D - boolean array.
width | Absolute width of the maze. |
height | Absolute height of the maze. |
void RecursiveDivision::makeMazeOpening | ( | bool ** | field, |
int | rows, | ||
int | cols | ||
) |
Make the start and end opening of the maze.
It consumes the absolute width and the relative rows to calculate a random opening and closing passage.
field | The complete maze field. |
rows | The relative row count. |
cols | The absolute width. |
bool RecursiveDivision::debugMode = false |
Var to print maze after every division on console.
LabGraph* RecursiveDivision::labPrinter |
For UI printing;