Live Demo
Loading Snake Game...
Game Controls
Algorithm:
A* Pathfinding
Status:
Auto-Playing
Speed:
60 FPS
A* Algorithm
What is A*?
A* is a pathfinding algorithm that finds the shortest path between two points while being more efficient than Dijkstra's algorithm by using a heuristic function to guide the search.
Time: O(b^d)
Space: O(b^d)
Key Features
- Uses heuristic function (Manhattan distance) to guide search
- Guarantees optimal path when heuristic is admissible
- More efficient than Dijkstra's for most cases
- Maintains open and closed lists for exploration
- Calculates f(n) = g(n) + h(n) for node evaluation
How it Works
- Starts from snake's current position
- Explores neighboring cells using 4-directional movement
- Calculates cost to reach each cell (g) and estimated cost to goal (h)
- Always expands the node with lowest f = g + h
- Backtracks to find the optimal path once goal is reached