A C++20 desktop application that visualizes A* and Dijkstra shortest-path algorithms on a 2D grid. Built with SFML 3 for rendering and TGUI for the user interface.
This project focuses on:
- incremental algorithms (non‑blocking UI)
- explicit data‑structure choices
- clean separation between grid, graph, algorithm, and UI
-
Interactive grid
- Left‑click to place/remove walls
-
Draggable Start & End nodes
- Drag with mouse
- Dropping on a wall removes the wall automatically
- Start and End cannot be swapped directly
-
Incremental pathfinding visualization
- Supports A* and Dijkstra
- Runs one step per frame (
step) - UI never freezes during execution
-
Algorithm selector (A* / Dijkstra)
-
Adjustable animation speed (1-100 ms per step)
-
8‑direction movement (horizontal, vertical, diagonal)
-
Event‑driven rendering
- Window redraws only when state changes
- Left Click on grid cell → Toggle Wall / Empty
- Drag Start or End cell → Move node
- Algorithm Selector → Choose
A*orDijkstra - Visualize → Start selected pathfinding algorithm
- Reset → Clear walls & reset algorithm state
- Animation Speed Slider → Delay per step (ms)
- Grid is converted into an adjacency list graph:
std::unordered_map<
Pair,
std::unordered_set<Pair, PairHash>,
PairHash
> adjList;- Nodes are removed/added dynamically when walls change
- Each cell may have up to 8 neighbors
- Horizontal / Vertical:
1.0 - Diagonal:
1.41421356(√2)
- Diagonal (Octile) Distance:
h = (dx + dy) + (√2 − 2) * min(dx, dy)- Admissible and consistent for 8‑direction movement
-
Implemented in
AStarRunnerandDijkstraRunner -
Both use:
priority_queuefor open listunordered_setfor closed listunordered_mapfor parent/cost details
-
Both algorithms advance one expansion per step
- Discovered → Node added to open list
- Visited → Node expanded (closed list)
- Path → Final reconstructed shortest path
-
Non‑blocking algorithm (incremental stepping)
-
No full redraw loop
- Redraw occurs only when:
- grid state changes
- UI interaction happens
- selected algorithm expands or updates nodes
- Redraw occurs only when:
-
Custom hash for
std::pair<int, int>to enable fast unordered containers
- CMake ≥ 3.29
- C++20 compiler (MSVC recommended for windows)
- vcpkg platform independent dependency manager (manifest mode)
sfml≥ 3.0.2tgui≥ 1.8.0
This project uses vcpkg manifest mode, so dependencies are installed automatically.
Windows
git clone https://github.com/microsoft/vcpkg
cd vcpkg
.\bootstrap-vcpkg.batLinux / macOS
git clone https://github.com/microsoft/vcpkg
cd vcpkg
./bootstrap-vcpkg.shWindows
git clone https://github.com/JagritThukral/grid-pathfinding-visualizer
cd grid-pathfinding-visualizer
cmake -S . -B build \
-DCMAKE_TOOLCHAIN_FILE=C:\path\to\vcpkg\scripts\buildsystems\vcpkg.cmake \
-DVCPKG_TARGET_TRIPLET=x64-windows
cmake --build build --config DebugLinux / macOS
git clone https://github.com/JagritThukral/grid-pathfinding-visualizer
cd grid-pathfinding-visualizer
cmake -S . -B build \
-DCMAKE_TOOLCHAIN_FILE=/path/to/vcpkg/scripts/buildsystems/vcpkg.cmake
cmake --build build --config DebugTo create Release builds, replace
DebugwithRelease.
.\build\Debug\project_pathfinding_grid.exe./build/Debug/project_pathfinding_gridFor Release builds, replace
DebugwithRelease.
grid-pathfinding-visualizer/
│
├─ main.cpp # Window loop, input handling, and algorithm stepping
│
├─ graph/
│ ├─ Graph.hpp/.cpp # Adjacency list + heuristic
│ ├─ AStarRunner.hpp/.cpp # Incremental A* implementation
│ ├─ DijkstraRunner.hpp/.cpp # Incremental Dijkstra implementation
│ └─ StepResult.hpp # Shared algorithm step result
│
├─ grid/
│ ├─ Cell.hpp/.cpp # Cell state & rendering
│
├─ ui/
│ ├─ UIManager.hpp/.cpp # TGUI panels, controls, legend
│
├─ utils/
│ ├─ Constants.hpp # Grid size, colors, layout, directions
│ ├─ PairHash.hpp # Hash for std::pair<int,int>
│ └─ RoundedRectangle.hpp # Custom rounded rectangle shape
│
├─ CMakeLists.txt
├─ vcpkg.json
└─ README.md
Most visual and layout parameters can be changed in:
utils/Constants.hpp
Including:
- Grid rows & columns
- Cell size & padding
- Colors for each cell state
- UI layout and panel dimensions
-
SFML / TGUI not found
- Ensure
-DCMAKE_TOOLCHAIN_FILE=.../vcpkg.cmakeis passed - Make sure vcpkg is bootstrapped
- Ensure
-
Runtime DLL errors
- Ensure vcpkg’s installed DLL directory is on
PATH
- Ensure vcpkg’s installed DLL directory is on
-
Nothing redraws
- Rendering is event-driven by design
- UI actions or algorithm steps must trigger redraw flags
- Current algorithms: A* and Dijkstra
- Architecture allows easy extension to:
- BFS / DFS
- Weighted grids
Made by Jagrit Thukral


