Dynamic AI Pathfinder 🚀
In the world of Artificial Intelligence, pathfinding is a fundamental challenge. Whether it's a GPS navigating city streets or a character in a video game moving through a map, the logic remains the same: how do we get from Point A to Point B?
For my latest project in AI 2002 – Artificial Intelligence, I developed a Dynamic AI Pathfinder. This isn't just a static maze solver; it's an interactive simulation that visualizes the "thinking process" of six core uninformed search algorithms in real-time.
🧠 The Challenge: Navigating the UnknownThe task was to build a Graphical User Interface (GUI) that demonstrates how different "blind" search strategies explore a grid. To make things interesting, the environment is dynamic. While the agent is moving, obstacles can randomly spawn, forcing the AI to detect the blockage and re-calculate its path on the fly.
🛠️ The Algorithms Under the HoodI implemented six fundamental search strategies:
- Breadth-First Search (BFS): Explores the grid layer by layer, guaranteeing the shortest path in an unweighted grid.
- Depth-First Search (DFS): Dives deep into one direction before backtracking.
- Uniform-Cost Search (UCS): Finds the optimal path based on cumulative cost.
- Depth-Limited Search (DLS): A DFS variant that prevents infinite loops by setting a maximum depth.
- Iterative Deepening DFS (IDDFS): Combines the space-efficiency of DFS with the optimality of BFS.
- Bidirectional Search: Simultaneously searches from both the start and the target to meet in the middle.
To ensure the search was consistent, I followed a strict clockwise expansion order. Every algorithm explores neighbors in this order:
- Up ⬆️
- Right ➡️
- Bottom ⬇️
- Bottom-Right (Diagonal) ↘️
- Left ⬅️
- Top-Left (Diagonal) ↖️
- And all other diagonal directions!
The real-world twist? Dynamic Obstacles. With a defined probability, a hurdle can spawn at any random empty location during each step of the algorithm. If the path is blocked, the AI triggers a "re-planning" sequence to find a new route to the target.
🎨 Visualization: Watching the AI "Flood" the GridA console output wouldn't do this justice. Using Pygame, I built a GUI titled "GOOD PERFORMANCE TIME APP". The interface distinguishes between:
- Frontier Nodes: Nodes waiting in the queue to be explored.
- Explored Nodes: Nodes already visited by the AI.
- Final Path: The successful route from Start to Target.
The animation runs with a slight delay, allowing you to watch the search algorithm "flood" the grid as it hunts for the destination.