|
qHexWalker 0.0.1
Hexagonal Grid Pathfinding & Maze Visualization on Interactive Maps
|
Generates perfect mazes on H3 hexagonal grids. More...
#include <h3MazeGenerator.h>
Inheritance diagram for H3MazeGenerator:
Collaboration diagram for H3MazeGenerator:Classes | |
| struct | H3IndexHash |
| Hash function for H3Index in unordered containers. More... | |
| struct | MazeResult |
| Result structure containing generated maze data. More... | |
Public Member Functions | |
| H3MazeGenerator (QObject *parent=nullptr) | |
| Constructs an H3MazeGenerator. | |
| ~H3MazeGenerator () override=default | |
| Default destructor. | |
| std::unordered_set< H3Index > | generateMaze (H3Index centerCell, int radius) |
| Generates a maze centered at the given cell. | |
| MazeResult | generateMazeWithEntrances (H3Index centerCell, int radius) |
| Generates a maze with entrance and exit points. | |
| void | mazeGenerated (const std::unordered_set< H3Index > &walls) |
| Emitted when maze generation is complete. | |
Public Attributes | |
| : void generationProgress(int percent) | |
Private Member Functions | |
| std::array< H3Index, 6 > | getNeighbors (H3Index cell) |
| Gets the 6 neighbors of a hexagonal cell. | |
| std::unordered_set< H3Index, H3IndexHash > | createRoomGrid (const std::unordered_set< H3Index, H3IndexHash > &allCells) |
| Creates a sparse room grid with minimum 2-cell spacing. | |
| std::optional< H3Index > | findWallBetween (H3Index room1, H3Index room2) |
| Finds the wall cell between two rooms. | |
| std::unordered_set< H3Index, H3IndexHash > | generateMazePrim (const std::unordered_set< H3Index, H3IndexHash > &rooms) |
| Generates maze passages using randomized Prim's algorithm. | |
| H3Index | findFarthestRoom (H3Index start, const std::unordered_set< H3Index, H3IndexHash > &passages) |
| Finds the room farthest from the start using BFS. | |
Static Private Member Functions | |
| static std::unordered_set< H3Index, H3IndexHash > | getCellsInRadius (H3Index center, int radius) |
| Gets all cells within a radius of the center. | |
| static std::vector< H3Index > | getRoomNeighbors (H3Index room, const std::unordered_set< H3Index, H3IndexHash > &rooms) |
| Gets rooms that are neighbors at distance 2. | |
| static bool | isOnBorder (H3Index cell, H3Index center, int radius) |
| Checks if a cell is on the border of the maze area. | |
Private Attributes | |
| std::mt19937 | rng_ |
| Random number generator for maze randomization. | |
| std::array< H3Index, 6 > | neighbors_ {} |
| Temporary storage for neighbor cells. | |
Generates perfect mazes on H3 hexagonal grids.
The H3MazeGenerator uses a modified Prim's algorithm to create perfect mazes (mazes with exactly one solution path) on hexagonal grids.
Definition at line 45 of file h3MazeGenerator.h.
| struct H3MazeGenerator::MazeResult |
Result structure containing generated maze data.
Definition at line 72 of file h3MazeGenerator.h.
Collaboration diagram for H3MazeGenerator::MazeResult:| Class Members | ||
|---|---|---|
| H3Index | entrance | Entry point cell index. |
| H3Index | exit | Exit point cell index. |
| unordered_set< H3Index > | walls | Set of wall cell indices. |
|
explicit |
Constructs an H3MazeGenerator.
| parent | Optional parent QObject for memory management. |
Definition at line 5 of file h3MazeGenerator.cpp.
|
overridedefault |
Default destructor.
|
private |
Creates a sparse room grid with minimum 2-cell spacing.
Rooms are the passable cells in the maze. This method ensures rooms are separated by at least 2 cells to allow walls between them.
| allCells | Set of all available cells. |
Definition at line 59 of file h3MazeGenerator.cpp.
References getNeighbors().
Referenced by generateMazeWithEntrances().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Finds the room farthest from the start using BFS.
Used to determine optimal entrance/exit placement.
| start | Starting room cell. |
| passages | Set of all passable cells. |
Definition at line 199 of file h3MazeGenerator.cpp.
References getNeighbors().
Referenced by generateMazeWithEntrances().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Finds the wall cell between two rooms.
Rooms are at distance 2 from each other; this finds the intermediate cell that acts as a wall.
| room1 | First room cell. |
| room2 | Second room cell. |
Definition at line 115 of file h3MazeGenerator.cpp.
References getNeighbors().
Referenced by generateMazePrim().
Here is the call graph for this function:
Here is the caller graph for this function:| std::unordered_set< H3Index > H3MazeGenerator::generateMaze | ( | H3Index | centerCell, |
| int | radius | ||
| ) |
Generates a maze centered at the given cell.
| centerCell | The H3 cell index at the maze center. |
| radius | The maze radius in cells. |
Definition at line 305 of file h3MazeGenerator.cpp.
References generateMazeWithEntrances().
Referenced by H3MazeAdapter::generateMaze().
Here is the call graph for this function:
Here is the caller graph for this function:
|
private |
Generates maze passages using randomized Prim's algorithm.
| rooms | Set of room cells. |
Definition at line 131 of file h3MazeGenerator.cpp.
References findWallBetween(), getRoomNeighbors(), and rng_.
Referenced by generateMazeWithEntrances().
Here is the call graph for this function:
Here is the caller graph for this function:| H3MazeGenerator::MazeResult H3MazeGenerator::generateMazeWithEntrances | ( | H3Index | centerCell, |
| int | radius | ||
| ) |
Generates a maze with entrance and exit points.
Creates a perfect maze with identified entry and exit points. The entrance and exit are placed at the farthest points from each other within the maze.
| centerCell | The H3 cell index at the maze center. |
| radius | The maze radius in cells. |
Definition at line 244 of file h3MazeGenerator.cpp.
References createRoomGrid(), findFarthestRoom(), generateMazePrim(), getCellsInRadius(), isOnBorder(), mazeGenerated(), and rng_.
Referenced by generateMaze().
Here is the call graph for this function:
Here is the caller graph for this function:
|
staticprivate |
Gets all cells within a radius of the center.
| center | The center cell. |
| radius | The radius in cells. |
Definition at line 27 of file h3MazeGenerator.cpp.
Referenced by generateMazeWithEntrances().
Here is the caller graph for this function:
|
private |
Gets the 6 neighbors of a hexagonal cell.
| cell | The cell to get neighbors for. |
Definition at line 7 of file h3MazeGenerator.cpp.
References neighbors_.
Referenced by createRoomGrid(), findFarthestRoom(), and findWallBetween().
Here is the caller graph for this function:
|
staticprivate |
Gets rooms that are neighbors at distance 2.
| room | The room to find neighbors for. |
| rooms | Set of all rooms. |
Definition at line 83 of file h3MazeGenerator.cpp.
Referenced by generateMazePrim().
Here is the caller graph for this function:
|
staticprivate |
Checks if a cell is on the border of the maze area.
| cell | The cell to check. |
| center | The maze center cell. |
| radius | The maze radius. |
Definition at line 233 of file h3MazeGenerator.cpp.
Referenced by generateMazeWithEntrances().
Here is the caller graph for this function:| void H3MazeGenerator::mazeGenerated | ( | const std::unordered_set< H3Index > & | walls | ) |
Emitted when maze generation is complete.
| walls | Set of wall cell indices. |
Referenced by generateMazeWithEntrances().
Here is the caller graph for this function:| H3MazeGenerator::__pad0__ |
Definition at line 105 of file h3MazeGenerator.h.
|
private |
Temporary storage for neighbor cells.
Definition at line 125 of file h3MazeGenerator.h.
Referenced by getNeighbors().
|
private |
Random number generator for maze randomization.
Definition at line 122 of file h3MazeGenerator.h.
Referenced by generateMazePrim(), and generateMazeWithEntrances().