qHexWalker 0.0.1
Hexagonal Grid Pathfinding & Maze Visualization on Interactive Maps
Loading...
Searching...
No Matches
h3MazeGenerator.h
Go to the documentation of this file.
1
12#pragma once
13
14#include <random>
15
45class H3MazeGenerator final : public QObject {
46 Q_OBJECT
47
48public:
53 explicit H3MazeGenerator(QObject *parent = nullptr);
54
58 ~H3MazeGenerator() override = default;
59
64 struct H3IndexHash {
65 std::size_t operator()(const H3Index &index) const { return std::hash<uint64_t>()(index); }
66 };
67
72 struct MazeResult {
73 std::unordered_set<H3Index> walls;
74 H3Index entrance;
75 H3Index exit;
76 };
77
87 std::unordered_set<H3Index> generateMaze(H3Index centerCell, int radius);
88
105 MazeResult generateMazeWithEntrances(H3Index centerCell, int radius);
106
107signals:
112 void generationProgress(int percent);
113
118 void mazeGenerated(const std::unordered_set<H3Index> &walls);
119
120private:
122 std::mt19937 rng_;
123
125 std::array<H3Index, 6> neighbors_{};
126
132 std::array<H3Index, 6> getNeighbors(H3Index cell);
133
141 static std::unordered_set<H3Index, H3IndexHash> getCellsInRadius(H3Index center, int radius);
142
152 std::unordered_set<H3Index, H3IndexHash> createRoomGrid(const std::unordered_set<H3Index, H3IndexHash> &allCells);
153
164 std::optional<H3Index> findWallBetween(H3Index room1, H3Index room2);
165
172 std::unordered_set<H3Index, H3IndexHash> generateMazePrim(const std::unordered_set<H3Index, H3IndexHash> &rooms);
173
181 static std::vector<H3Index> getRoomNeighbors(H3Index room, const std::unordered_set<H3Index, H3IndexHash> &rooms);
182
192 H3Index findFarthestRoom(H3Index start, const std::unordered_set<H3Index, H3IndexHash> &passages);
193
202 static bool isOnBorder(H3Index cell, H3Index center, int radius);
203};
Generates perfect mazes on H3 hexagonal grids.
~H3MazeGenerator() override=default
Default destructor.
H3Index exit
Exit point cell index.
std::array< H3Index, 6 > getNeighbors(H3Index cell)
Gets the 6 neighbors of a hexagonal cell.
static std::vector< H3Index > getRoomNeighbors(H3Index room, const std::unordered_set< H3Index, H3IndexHash > &rooms)
Gets rooms that are neighbors at distance 2.
MazeResult generateMazeWithEntrances(H3Index centerCell, int radius)
Generates a maze with entrance and exit points.
std::unordered_set< H3Index, H3IndexHash > generateMazePrim(const std::unordered_set< H3Index, H3IndexHash > &rooms)
Generates maze passages using randomized Prim's algorithm.
std::unordered_set< H3Index, H3IndexHash > createRoomGrid(const std::unordered_set< H3Index, H3IndexHash > &allCells)
Creates a sparse room grid with minimum 2-cell spacing.
std::unordered_set< H3Index > generateMaze(H3Index centerCell, int radius)
Generates a maze centered at the given cell.
H3Index entrance
Entry point cell index.
std::array< H3Index, 6 > neighbors_
Temporary storage for neighbor cells.
void mazeGenerated(const std::unordered_set< H3Index > &walls)
Emitted when maze generation is complete.
std::unordered_set< H3Index > walls
Set of wall cell indices.
std::optional< H3Index > findWallBetween(H3Index room1, H3Index room2)
Finds the wall cell between two rooms.
static bool isOnBorder(H3Index cell, H3Index center, int radius)
Checks if a cell is on the border of the maze area.
static std::unordered_set< H3Index, H3IndexHash > getCellsInRadius(H3Index center, int radius)
Gets all cells within a radius of the center.
std::mt19937 rng_
Random number generator for maze randomization.
H3Index findFarthestRoom(H3Index start, const std::unordered_set< H3Index, H3IndexHash > &passages)
Finds the room farthest from the start using BFS.
Result structure containing generated maze data.
Hash function for H3Index in unordered containers.
std::size_t operator()(const H3Index &index) const