PATHFINDING
A* (A-Star) is a pathfinding algorithm that finds the shortest route between two points by making educated guesses.
Think of it as a person in a maze holding a compass pointing to the exit.
How it works (The 3 Steps)
When a Ghost is at an intersection, A* looks at the available tiles and gives each one a "Score" (F) based on two numbers:
G-Cost (Distance Walked): How far have I travelled from the start to get here?
H-Cost (The Guess): How far is it from here to the target "as the crow flies"? (This is the compass part).
The Formula:
Score = Distance Walked + Distance Left
The Difference
Dumb Pathfinding (Dijkstra): Checks every possible path in a circle, expanding outward like a puddle of water until it hits the target. It's accurate but slow.
A Pathfinding:* Checks the paths that point toward the target first. If a path moves away from the target, A* ignores it unless all other options are blocked.
In Pac-Man Terms
When a Ghost asks "Which way should I go?", A* calculates:
Left Turn: Moves away from Pac-Man. (High Score = Bad).
Right Turn: Moves closer to Pac-Man. (Low Score = Good).
The Ghost picks the lowest score and moves that way immediately.