This repository contains an implementation of the A* (A-Star) pathfinding algorithm in Python. The A* algorithm is a popular search algorithm used in various applications such as AI, robotics, and game development to find the shortest path between two points.
- A* Algorithm: Efficiently finds the shortest path between the start and goal nodes.
- Visualization: Provides a visual representation of the grid, obstacles, start, and goal nodes, and the path found by the algorithm.
- Interactive UI: Allows users to interact with the grid, set start and goal nodes, and add obstacles.
- Python 3.x
- Pygame
Clone the repository:
git clone https://github.com/Aftaab25/AStarPathfinder.git
cd AStarPathfinder
Run the A* pathfinding script using the following command:
python3 main.py
This will start the application, and you can interact with the grid to visualize the A* pathfinding algorithm.
Select the start and end point by clicking any of the box in the grid. (First click corresponds to the start point and the Second click corresponds to the end point)
Then click anywhere in the grid to draw obstacles in the path that the algorithm has to avoid.
Press Space
to start the visualization of the algorithm and see the result (the shortest path possible) drawn by the algorithm.
Press Enter
to clear the grid and draw new maps to play with.
- Imports: Necessary libraries including Pygame and heapq.
- Node Class: Represents a single node in the grid with attributes like position, cost, heuristic, and parent.
- A Algorithm*: Implements the A* search algorithm to find the shortest path.
- Visualization: Uses Pygame to visualize the grid, obstacles, start and goal nodes, and the path found by the algorithm.
- Event Handling: Handles user input for setting start and goal nodes, adding obstacles, and resetting the grid.
This project is licensed under the MIT License. See the LICENSE file for details.