Skip to content

Navigate & Optimise: Heuristic Pathfinding via Cost-Driven Node Evaluation and Visual Grid Simulation

License

Dancull/Heuristic-Pathfinding-Tool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

A* Pathfinding Visualisation Tool (C++ & SDL2)

A standalone visualisation of the A* pathfinding algorithm, built in C++ and rendered with SDL2. Designed to help developers, students, and game designers understand how A* works in real-time through interactive grid simulation.

Features

  • A Pathfinding Algorithm*: Efficiently finds the shortest path using a heuristic-based approach (f(n) = g(n) + h(n)).
  • Interactive Visualisation: Real-time rendering of nodes, paths, and visited cells using SDL2.
  • Custom Grid & Obstacles: Modify the environment by adding/removing obstacles on a 20x20 grid.
  • Manhattan Heuristic: Estimates shortest paths in grid-based maps (perfect for 4-direction movement).
  • Neighbour Node Calculation: Safely checks surrounding nodes while respecting map boundaries and obstacles.
  • Easter Egg Trigger: A fun, hidden feature triggered when the player resets the simulation — includes an AI-generated voice.
  • Modular Design: Easily adaptable for integration into simulation games, colony simulators, or AI navigation systems.

Prerequisites

  • C++11 (or later)
  • SDL2 development libraries installed
  • CMake (recommended for building)

Installation

# Clone the repository
git clone https://github.com/yourusername/a-star-pathfinding-visualiser.git

# Build using CMake
cd a-star-pathfinding-visualiser
mkdir build && cd build
cmake ..
make

# Run the program
./astar_visualiser

Controls

Action Description
Left Click Place the start and end nodes
Right Click Add/remove obstacles
Enter/Return Start the A* pathfinding algorithm
R Key Reset the simulation (triggers easter egg)
ESC Exit the application

License

Including a LICENSE file clarifies how others may use, modify, and distribute your code. By choosing an open-source license such as MIT, you grant permission for use under defined terms while protecting your intellectual property and limiting liability.

This project is licensed under the MIT License. See LICENSE for full details.

Project Structure

a-star-pathfinding-visualiser/
├── astar/                         # Core source code and assets
│   ├── astar.cpp                  # Main program entry point
│   ├── game.cpp                   # Handles simulation loop and input events
│   ├── game.h                     # Header for Game class and related methods
│   ├── grid.cpp                   # Logic for grid creation, obstacle placement, and node status
│   ├── grid.h                     # Grid structure definitions and constants
│   ├── pathfinding.cpp            # Implementation of the A* pathfinding algorithm
│   ├── pathfinding.h              # A* algorithm declarations and helper functions
│   ├── renderer.cpp               # SDL2 rendering logic for nodes, grid, and path
│   ├── renderer.h                 # Renderer class definitions and SDL2 includes
│   ├── easteregg.wav              # AI-generated audio clip played when reset is triggered
│   └── sound1.wav                 # Additional sound effect (e.g., on goal reached or path found)
│
├── x64/                           # Output build folder 
│   └── Debug/
│       └── astar.exe              # Compiled executable for debug testing
│
├── astar.sln                      # Visual Studio Solution file to build and run the project
└── README.md                      # Project documentation 

How It Works

  • Open List (Priority Queue): Stores nodes to explore, sorted by lowest f value.
  • Closed List: Keeps track of already-visited nodes.
  • Neighbour Checking: Checks left, right, up, and down directions.
  • Heuristic Function: Uses Manhattan Distance to guide the search.
  • Path Backtracking: Reconstructs the optimal path by following parent pointers from goal to start.

Roadmap

  • NPC pathfinding simulation for use in games
  • Variable terrain costs (e.g., grass, water, roads)
  • Larger grids and map importing
  • Multiple goal targets and patrol route support
  • Pathfinding performance analysis tool
  • GUI-based map editor for custom terrain
  • Export path as JSON or image
  • Mouse-hover node details in UI

Author

About

Navigate & Optimise: Heuristic Pathfinding via Cost-Driven Node Evaluation and Visual Grid Simulation

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages