Visual comparison of A*, Dijkstra, and Bellman-Ford algorithms with Pygame
simplescreenrecorder-2024-09-20_14.42.34.mp4
Try the interactive web version! Click the button above to explore pathfinding algorithms in your browser - no installation required.
This project implements and visualizes three popular pathfinding algorithms: A*, Dijkstra, and Bellman-Ford. Built with Python and Pygame, it provides an interactive way to understand how different algorithms find the shortest path on a weighted grid.
Smart and Fast
Uses both past cost and estimated distance to goal. Focuses toward the target, avoiding unnecessary exploration.
Advantages:
- ✅ Fastest algorithm
- ✅ Always finds optimal path
- ✅ Very efficient when goal is known
Classic and Guaranteed
Finds shortest path from start to all nodes. Explores equally in all directions without focusing on goal.
Advantages:
- ✅ Always correct results
- ✅ Finds shortest paths to all nodes
- ✅ Simple and clear logic
Flexible and Robust
Handles negative edge weights and detects negative cycles. Slower but more general-purpose.
Advantages:
- ✅ Supports negative edge weights
- ✅ Can detect negative cycles
- ✅ Works with complex graphs
pip install pygamepython main.py- Click on the grid to set a target destination
- The algorithm will automatically calculate and display the shortest path
- Green circle = Start position
- Red circle = Target position
- Blue circles = Shortest path
Open main.py and uncomment the algorithm you want to use (lines 72-74):
visited = a_star(graph, start, mouse_pos) # A* Algorithm
# visited = dijkstra(graph, start, mouse_pos) # Dijkstra Algorithm
# visited = bellman_ford(graph, start, mouse_pos) # Bellman-Ford Algorithm- Interactive Visualization - Real-time pathfinding
- Weighted Grid - Different terrain costs (1-9)
- Multiple Algorithms - A*, Dijkstra, Bellman-Ford
- Visual Feedback - Color-coded paths and nodes
Bu proje, üç popüler yol bulma algoritmasını uygular ve görselleştirir: A*, Dijkstra ve Bellman-Ford. Python ve Pygame ile oluşturulmuş, farklı algoritmaların ağırlıklı bir grid üzerinde en kısa yolu nasıl bulduğunu anlamak için interaktif bir yol sunar.
Akıllı ve Hızlı
Hem geçmiş maliyeti hem de hedefe tahmini mesafeyi kullanır. Hedefe doğru odaklanarak gereksiz yolları keşfetmez.
Avantajları:
- ✅ En hızlı algoritma
- ✅ Her zaman optimal yolu bulur
- ✅ Hedef bilinen durumlarda çok verimli
Klasik ve Garantili
Başlangıçtan her noktaya en kısa yolu bulur. Tüm yönlere eşit şekilde yayılarak ilerler, hedefe odaklanmaz.
Avantajları:
- ✅ Her zaman doğru sonuç verir
- ✅ Tüm noktalara en kısa yolu bulur
- ✅ Basit ve anlaşılır mantık
Esnek ve Güçlü
Negatif maliyetli yolları destekler ve negatif döngüleri tespit eder. Daha yavaş ama daha genel amaçlı.
Avantajları:
- ✅ Negatif ağırlıklı kenarları destekler
- ✅ Negatif döngü tespiti yapabilir
- ✅ Karmaşık graflar için uygundur
pip install pygamepython main.py- Grid üzerinde tıklayarak hedef konumu belirleyin
- Algoritma otomatik olarak en kısa yolu hesaplayıp gösterecektir
- Yeşil çember = Başlangıç noktası
- Kırmızı çember = Hedef noktası
- Mavi çemberler = En kısa yol
main.py dosyasını açın ve kullanmak istediğiniz algoritmayı aktif edin (72-74. satırlar):
visited = a_star(graph, start, mouse_pos) # A* Algoritması
# visited = dijkstra(graph, start, mouse_pos) # Dijkstra Algoritması
# visited = bellman_ford(graph, start, mouse_pos) # Bellman-Ford Algoritması- İnteraktif Görselleştirme - Gerçek zamanlı yol bulma
- Ağırlıklı Grid - Farklı arazi maliyetleri (1-9)
- Çoklu Algoritmalar - A*, Dijkstra, Bellman-Ford
- Görsel Geri Bildirim - Renkle kodlanmış yollar ve düğümler