huc::maze::RecursiveDivisionGenerator Class Reference

#include <recursive_division_generator.hxx>

Public Types

typedef Grid< CellInfoBaseMaze
 
typedef Maze::Cell Cell
 
typedef Maze::Point Point
 

Public Member Functions

std::unique_ptr< Mazeoperator() (const uint32_t width, const uint32_t height, const uint32_t seed=0)
 

Static Private Member Functions

static void Compute (std::mt19937 &mt, Maze &maze, const Point &origin, const uint32_t width, uint32_t height)
 

Detailed Description

Recursive Division Generator - Generate a maze using a recursive division strategy.

Recursive Division Maze Generator is the fastest algorithm without directional biases. While Recursive division really stands out with respect to parallelism, this algorithm is particularly fascinating because of its fractal nature: you could theoretically continue the process indefinitely at finer and finer levels of detail (smaller and smaller scales).

This algorithm is somewhat similar to recursive backtracking, since they're both stack based, except this focuses on walls instead of passages. As a Wall Builders generator, the process begins with a large empty space (all cells are connected), and adds walls (disconnect cells) until a maze results.

Parameters
widthdesired width for the maze.
heightdesired height for the maze.
seednumber used to initiate the random generator.
Returns
Operator() returns Maze Grid pointer to be owned, nullptr if construction failed.

Definition at line 50 of file recursive_division_generator.hxx.

Member Typedef Documentation

Member Function Documentation

static void huc::maze::RecursiveDivisionGenerator::Compute ( std::mt19937 &  mt,
Maze maze,
const Point origin,
const uint32_t  width,
uint32_t  height 
)
inlinestaticprivate

Definition at line 72 of file recursive_division_generator.hxx.

73  {
74  if (width < 2 || height < 2)
75  return;
76 
77  // Build a wall within the room, whether vertical or horizontal,
78  // Open a gate at a random position
79  bool isHorizontalCut = (mt() % 2 == 0) ? true : false; //(width <= height);
80  uint32_t wallIdx = (isHorizontalCut) ? mt() % (height - 1) : mt() % (width - 1);
81  uint32_t pathIdx = (isHorizontalCut) ? mt() % width : mt() % height;
82 
83  // Build wall and Recurse on sub areas (Top and Bottom)
84  if (isHorizontalCut)
85  {
86  maze.DisconnectRow(origin, wallIdx, width, pathIdx);
87  Compute(mt, maze, origin, width, wallIdx + 1);
88  Compute(mt, maze, Point(origin.x, origin.y + wallIdx + 1), width, height - wallIdx - 1);
89  }
90  // Recurse on sub areas (Left and Right)
91  else
92  {
93  maze.DisconnectCol(origin, wallIdx, height, pathIdx);
94  Compute(mt, maze, origin, wallIdx + 1, height);
95  Compute(mt, maze, Point(origin.x + wallIdx + 1, origin.y), width - wallIdx - 1, height);
96  }
97  }
static void Compute(std::mt19937 &mt, Maze &maze, const Point &origin, const uint32_t width, uint32_t height)
std::unique_ptr<Maze> huc::maze::RecursiveDivisionGenerator::operator() ( const uint32_t  width,
const uint32_t  height,
const uint32_t  seed = 0 
)
inline

Definition at line 57 of file recursive_division_generator.hxx.

58  {
59  if (width < 1 || height < 1)
60  return nullptr;
61 
62  auto maze(std::unique_ptr<Maze>(new Maze(width, height, true)));
63  std::mt19937 mt(seed); // Initialize random generator (Mersenne Twister)
64 
65  Compute(mt, *maze, Point(0,0), width, height);
66 
67  return maze;
68  }
static void Compute(std::mt19937 &mt, Maze &maze, const Point &origin, const uint32_t width, uint32_t height)

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