- A pathfinding simulator using SFML(Simple and Fast Multimedia Library) for comparing optimality and speed of Dijkstra and A* algorithms.
- Simulation video: Here
-
Color coding :
- Open cells - White
- Blocked cells - Black
- Start and End cells - Blue and Red
- Explored cells - Yellow
- Shortest Path of Dijkstra and A-star - Green and Magenta
-
Major components :
- Main loop to render frames at 60 frames/second
- Dijkstra program
- Astar program
-
Implementation :
- Map as 2D array of cells
- Binary representation of cells as 0 and 1 for blocked and open cells
- Each cell has information of its parent and its state of exploration
-
Heuristics for a node having coordinates
(node_x, node_y)
is :- Horizontal and vertical cost:
D1 = 1
- Diagonal cost:
D2 = √2
- Abscissa difference:
dx = |goal_x – node_x|
- Ordinate difference:
dy = |goal_y – node_y|
- Diagonal heuristics:
h = D1* |dx - dy| + D2* min(dx, dy)
- Horizontal and vertical cost:
-
If you are using non-Linux OS, then see how to build SFML and compile programs for your Operating System here
-
If you are using Ubuntu or other Linux distros, then for a quick compilation:
- Clone the repository:
git clone https://github.com/UditSinghParihar/Pathfinding_Simulator
cd Pathfinding_Simulator
- Install sfml:
sudo apt-get install libsfml-dev
- Complile simulator.cpp :
g++ simulator.cpp -std=c++11 -lsfml-window -lsfml-system -lsfml-graphics
- Run the exectuable :
./a.out
- Clone the repository:
- Place the text in button menu.
- Add smooth selection of blocking cells(obstacle cells), by clicking left mouse and hovering over the cells.
- Add CMake build system for easy compilation.
- Refactoring code into headers and OOPS style.