leistungsnachweis-cas
 All Classes Functions Variables Friends
Public Member Functions | Public Attributes | List of all members
RecursiveDivision Class Reference

#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

LabGraphlabPrinter
 
bool debugMode = false
 

Detailed Description

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.

Member Function Documentation

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.

Parameters
fieldThe complete maze field.
leftThe column index of the left column.
rightThe column index of the right column.
topThe row index of the top row.
bottomThe 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.

Parameters
fieldThe complete maze field.
leftThe column index of the left column.
rightThe column index of the right column.
topThe row index of the top row.
bottomThe 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.

Parameters
fieldThe complete maze field.
leftThe column index of the left column.
rightThe column index of the right column.
topThe row index of the top row.
bottomThe 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.

Parameters
fieldMaze field.
outputoutput 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.

Parameters
isinput-stream for reading input params.
Returns
0 if no exception occurs.

Enable Debug mode for maze printing:

bool RecursiveDivision::generateRandomBoolean ( )

Generate a random boolean value.

Returns
random true or false.
int RecursiveDivision::generateRandomInt ( int  lower,
int  upper 
)

Generate a random integer value between the lower and the upper boundary.

Parameters
lowerLower bound.
upperUpper bound.
Returns
random value.
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.

Parameters
widthAbsolute width of the maze.
heightAbsolute height of the maze.
Returns
The generated maze field as 2D bool array.
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.

Parameters
fieldThe complete maze field.
rowsThe relative row count.
colsThe absolute width.

Member Data Documentation

bool RecursiveDivision::debugMode = false

Var to print maze after every division on console.

LabGraph* RecursiveDivision::labPrinter

For UI printing;


The documentation for this class was generated from the following files: