I was obsessed with Pac-Man a kid -- I'm old enough to have played it back when it was originally in arcades, and I even bought the book Mastering Pac-Man for the patterns. (I eventually got good enough at those patterns I rolled the machine over twice, which took I think about four hours? Enough that I was kind of a mess afterwards physically.)
Basically the ghosts have three modes -- either they're chasing you, they're "scattering", or they're in the "scared" mode where you can eat them. In any of those cases, they pick a target they're heading towards, and use that target to figure out what they should do when they get to an intersection: Turn or not?
It turns out the reason the red ghost is so aggressive is that when it's in chase mode, its target is you -- it's aiming at the precise spot where Pac-Man currently is.
The pink ghost has a slightly weirder method of chasing you. It doesn't aim at you directly; it aims four "tiles" away from you, like here ...
... and this is why it's possible to sometimes play a game of chicken with the pink ghost. As he writes ...
Since his target tile is set four tiles in front of Pac-Man, if Pac-Man heads directly towards him, Pinky's target tile will actually be behind himself once they are less than four tiles apart. This will cause Pinky to choose to take any available turn-off in order to loop back around to his target. Because of this, it is a common strategy to momentarily "fake" back towards Pinky if he starts following closely. This will often send him off in an entirely different direction.
A pic of that ...
That's wild. I knew that behavior existed -- I'd figured out, through trial and error, that you could do this with the pink ghost. But it's fascinating to now understand the ruleset that explains why it's possible.
The blue ghost's algorithm is even crazier. It aims at a spot that is combination of your position and the red ghost's position. This explains why the blue ghost's behavior can vary so dramatically. If the red ghost happens to be far away from you, then the blue ghost is triangulating some destination that is itself quite distant from you, and it looks ... sort of lost. But if the red ghost gets close to you, then the blue ghost's triangulated position becomes much, much closer to you itself, and its behavior begins, rather abruptly, to appear "smarter".
Dangerously smart, I might add. There's an interesting emergent aspect of this triangulated targeting. When the red ghost is close to you, the blue ghost is going to chasing a spot that is near you but not on you -- which means the blue ghost might wind up flanking you into a corner. Devious!
One rather poetic side note: The are periods in each level when the ghosts are in "scatter" mode, and they stop chasing you, giving you a temporary breather. But where, precisely, are they heading during "scatter" mode? They're aiming at spots outside the maze.
This is some straight-up pre-Copernical medieval cosmology, and I love it. The ghosts are, however briefly, aiming at a spot outside the shell of their universe, some point that exists in the aeth'rial realms they are forbidden to visit. Which could make one playfully wonder, pondering the interior psychology of retro-game characters -- are they aware that the spot at which they aim is offworld? Or do they just sense the pull of some distant star, its hungry gravity?
Heh. Anyway, the destinations in this "scatter" mode come into play when understanding the chase mode of the last ghost, the orange one. That's because it has a fascinating shelf that suddenly changes its chase pattern. If it's more than eight tiles away from you, it behaves the red ghost, heading straight for your position with the laser focus of a great white shark.
But if it gets less than eight tiles from you? It suddenly changes its target to its outside-the-maze spot that it aims at during "scatter" mode.
The combination of these two methods has the overall effect of Clyde alternating between coming directly towards Pac-Man, and then changing his mind and heading back to his corner whenever he gets too close. On the diagram above, the X marks on the path represent the points where Clyde's mode switches. If Pac-Man somehow managed to remain stationary in that position, Clyde would indefinitely loop around that T-shaped area.
You should go read the entire analysis -- there's a lot more depth to it, and I'm only scraping the surface here.
But I'm curious to see, if I played Pac-Man again now, whether any of this knowledge would help me play it in a fresh fashion. I mean, I used to play it merely relying on the patterns I'd learned, so I was like a goddamned robot on the Chrysler auto-manufacturing line, numbly executing my moves while paying no attention to anything else. But were I to actually play the game -- i.e. try to elude the ghosts dynamically, by observing their movements -- maybe this info would help me make better rapid mental-chess decisions.
Either way, I'd love to see more such analyses of the algorithmic rulesets behind other retro games. The invisibility of game mechanics creates an interesting culture around it: When we don't have direct info on the algorithms behind our NPC opponents, we sort of reverse-engineer them, intuiting the dark and invisible laws that they behave, set down by their creator. There's something clearly pleasant in that; it's a key part of what makes video games fun. But there's something enthralling, too, about having precise knowledge of those rulesets -- so one can sit back and play them out in the model of one's mind, using them like Newton's laws of physics to iterate through possible interactions of the characters in the game.