A C++ application that visualize various pathfinding algorithms and maze generation strategies on a 2D grid using the SFML library.
The project is built using the Strategy Design Pattern to allow for easy interchangeability and extension of algorithms.
- Path Finding: The
Path_finder_contextmanages the active pathfinding strategy. All algorithms implement theIPath_finderinterface. - Maze Generation: The
Maze_generator_contextmanages the maze generation strategy. All generators implement theIMaze_generatorinterface.
This design makes it simple to add new algorithms without modifying the core simulation logic.
Currently, the following pathfinding algorithms are implemented:
- BFS (Breadth-First Search): Explores the grid layer by layer. It guarantees the shortest path in an unweighted grid.
- DFS (Depth-First Search): Explores as deep as possible along each branch before backtracking. It does not guarantee the shortest path.
- Dummy Generator: Clears the map (creates an empty grid).
- DFS (Recursive Backtracker): Generates mazes with long, winding corridors and few dead ends.
- BFS (Randomized): Generates mazes with a branching structure, often resulting in a more "bushy" texture compared to DFS.
We are actively working on expanding the simulation with more complex and interesting algorithms.
- Dijkstra's Algorithm: For finding the shortest paths in weighted graphs.
- A (A-Star):* An optimized search algorithm using heuristics to find the shortest path faster.
- RRT (Rapidly-exploring Random Tree): A probabilistic algorithm designed for high-dimensional search spaces (adapted for grid use).
- Randomized Prim's Algorithm: Grows the maze from a starting cell by adding random frontier walls, creating a Minimum Spanning Tree (MST) structure.
- Kruskal's Algorithm: Uses a disjoint-set data structure to randomly merge sets of cells, creating a maze with a distinct texture.
- C++ Compiler: Compatible with C++23 standard (e.g., GCC 13+, Clang, MSVC).
- CMake: Version 3.16 or higher.
- SFML: Version 2.6.x (System, Window, Graphics modules).
-
Clone the repository:
git clone <repository-url> cd GridSimulator
-
Configure the project:
cmake -S . -B build -
Build the executable:
cmake --build build
-
Run the application:
./build/GridSimulator
This project has AddressSanitizer (ASan) and UndefinedBehaviorSanitizer (UBSan) enabled in the build configuration to help detect memory errors and undefined behavior.
To use it:
- Build the project as described above. The flags
-fsanitize=address -fsanitize=undefinedare already active. - Run the application. If a memory issue (like out-of-bounds access) occurs, the application will crash and print a detailed error report to the terminal.
Note: running with sanitizers might slow down the application slightly.
| Key | Action |
|---|---|
1 |
Select BFS Path Finder |
2 |
Select DFS Path Finder |
3 |
Select Dummy Maze Generator (Empty Map) |
4 |
Select DFS Maze Generator |
S |
Start Pathfinding (Selects random start/end points) |
G |
Generate Maze (using selected generator) |
P |
Pause / Resume Simulation |
R |
Reset Simulation (Clear map and states) |
src/: Source code files.Grid/: Grid visualization logic.maze_generators/: Maze generation algorithms (Strategy Pattern).path_finders/: Pathfinding algorithms (Strategy Pattern).utils/: Utility classes (Map,Cell,Coords,Random_engine).
doc/: Documentation files.cmake/: CMake configuration files.
