Skip to content

Latest commit

 

History

History
executable file
·
122 lines (86 loc) · 4.31 KB

File metadata and controls

executable file
·
122 lines (86 loc) · 4.31 KB

🧭 Pathfinding Visualizer (Pygame)

An interactive pathfinding visualizer built with Python and Pygame, allowing you to explore popular search algorithms in real time — such as A*, Dijkstra, BFS, DFS, and more.
You can draw walls, set start and goal nodes, and watch how different algorithms find their way through the grid.

A* Algorithm Visualization Randomized DFS Visualization


📁 Project Overview

This project provides a graphical simulation environment for visualizing how pathfinding algorithms explore a grid.

Features

  • 🎨 Interactive grid editor (add walls, start and goal nodes)
  • 🧮 Multiple pathfinding algorithms:
    • A* (A-Star)
    • Dijkstra’s Algorithm
    • Breadth-First Search (BFS)
    • Depth-First Search (DFS)
    • Greedy Best-First Search
    • Bidirectional BFS
    • Randomized DFS
    • Rapidly-Exploring Random Tree (RRT)
  • 🕒 Real-time animation and execution time display
  • 🧰 Simple, extensible architecture (easily add new algorithms)

⚙️ Requirements

Before running the project, make sure you have:

  • Python 3.8+
  • Pygame

You can install the dependencies with:

  pip install pygame

🚀 How to Run

  1. Clone or download this repository to your local machine.

  2. Navigate to the project folder, for example:

  cd "/my/folder/PathFinder"
  1. Run the main program:
   python main.py

or, depending on your setup:

py main.py
  1. The Pygame window should open — you can now start building walls, setting start and goal nodes, and visualizing pathfinding algorithms in action!

🕹️ How to Use

Action Description
🖱️ Left Click Place the start, goal, and walls (in that order, you can hold click when placing walls).
🖱️ Right Click Erase any cell.
🖱️ Left Click - Top Menu Click to switch between algorithms.
Spacebar Start the selected algorithm visualization.
🔁 R Reset the grid.
Close Window Quit the application.

🧩 Project Structure

PathFinder/
│
├── main.py # Entry point of the application
├── window.py # Game loop and event handling
├── config.py # Configurations and constants
├── menu.py # Algorithm selection menu
├── visualizer/
│ └── grid_visualizer.py # Grid rendering and interactions
└── algorithms/ # Algorithm implementations (A*, BFS, etc.)

🧠 How It Works

Each algorithm runs as a Python generator, yielding control each frame so that the grid can be updated and redrawn smoothly. This lets you visualize how nodes are visited step-by-step. The visualization layer (GridVisualizer) paints cells according to their type:

  • Start → 🔴 Red
  • Goal → 🟢 Green
  • Wall → ⚫ Black
  • Visited → 🔵 Dark blue
  • Path → 🟡 Yellow

🏗️ Extending the Project

To add a new algorithm:

  1. Create a new Python file in the algorithms/ directory (e.g. my_algorithm.py).
  2. Implement a class with a .run() generator method that yields control each iteration.
  3. Register the class in the ALGORITHMS dictionary inside window.py (use a user-friendly name as the key).

Example entry in window.py:

'My Algo': my_algorithm.MyAlgorithm

📜 License

This project is released under the MIT License — feel free to modify and use it for personal or educational purposes.