Sorry for the possible breach of newbie ettiquette by jumping in at this point, but the topic is too dang fascinating to resist.
Here is what I've been able to come up with about the ghost AI in the "attack" mode, to supplement what's in the "ghost psychology" link and the excellent observations you all have made.
* Red ghost (Oikake): Input is Pac-Man's location. He doesn't consider which direction Pac-Man is going. He attempts to reduce the distance between himself and Pac-Man. He will turn in the direction that will immediately reduce whichever is GREATER of the horizontal distance or vertical distance between himself and Pac-Man. This usually has him tenaciously following Pac-Man, but will occasionally lead to a "stupid" choice (see illustration below).
* Pink ghost (Machibuse): Input is four tiles in front of Pac-Man. Therefore direction Pac-Man is facing as well as actual location of Pac-Man determine Pinky's "target." Pinky attempts to home in on this target using the same logic as the Red ghost uses to home in on Pac-Man. This does indeed effectively "set up an ambush" if Pinky manages to get in front of you. At close range, the direction you face can mean life or death. If you're facing away from Pinky, he will chase you (his "target" is now in front of both you and him). If you face him or turn off to a side, he may turn away from you if that provides a shorter route to the target than running through you. Note that if the space four tiles in front of you is on the other side of a wall, he will go over there in preference to the side you are on.
* Blue ghost (Kimagure): Inputs, as mentioned, are the square two tiles in front of Pac-Man, and the location of the Red ghost. (Edited out incorrect information here and replaced with correct information that follows-->) To envision Inky's target, draw a line from the Red ghost to the spot 2 tiles in front of Pac-Man. Now extend that line twice as far in the same direction and draw an "x" where it winds up. Inky wants to reach that "x." The fact that Inky's AI has two inputs instead of one makes his behavior more complex. On a fast-moving playing field with Pac-Man and the red ghost constantly changing position, that "x" can be jumping all over the place and sometimes Inky's behavior seems completely random - but it's not. No wonder his alternate name on the Puck-Man rom is "Stylist"! His regular name, Kimagure ("Whimsy") is also appropriate. It makes sense that the closer the red ghost is to Pac-Man (technically, the closer he is to the spot two spaces in front of Pac-Man), the more predictable Inky's behavior appears. Thanks to JamieVegas and Dav for getting this right the first time. Sorry I temporarily had completely wrong information on here!
* Orange ghost (Otoboke): Has two modes, "near" (within 8 tiles of Pac-Man) and "far" (farther away than 8 tiles). In "far" mode, he heads toward Pac-Man using Blinky's logic. This gets him in the same general area of the maze, but then in "near" mode, he has a bizarre change of heart and decides to head for his corner of the maze (lower left island). Unless you happen to be in the lower left region, his about-face will soon take him into "far" mode again, and he will circle back toward your area. If you are in the lower left, he will circle his favorite island indefinitely. He will usually only "chase" you if you happen to be in the path between him and the lower left of the screen. Orange's "far" mode rarely leaves him doubled up on top of Red due to the fact that their home quadrants are on opposite sides of the map and "scatter" mode repeatedly separates them. Plus, red is usually close enough to you that orange will go into "near" mode if he gets close to red.
Here's an illustration where all 4 of the ghosts' strategies work against them -
Pac has been on the board long enough that there are no more "scatter" modes. The ghosts are in constant "attack." Since it's a cherry board, Red is not in accelerated "Cruise Elroy" mode, so all 4 ghosts are travelling at the same speed. This keeps Red just in front of Blue. The ghosts will go around these islands forever without finding Pac. Here's why -
Red: When he reaches the SW corner of his island and could potentially approach Pac-Man by going straight rather than turning N like an idiot, his algorithm considers the following... his vertical distance from Pac is greater than his horizontal distance... turning N reduces that vertical distance while continuing W does not... therefore, go north! And around he goes again.
Pink: As long as Pac stays still and doesn't turn W or S, Pink's target is a spot along the north side of the island. He'll go around and around forever, the shortest route to the target always being to keep going around since he can't reverse his direction.
Blue: The spot two tiles in front of Pac-Man is approximately at the NW corner of the island Blue is circling. When Blue reaches the SW corner each time around, Red will always be just N of him. The line from Red to the spot two tiles in front of Pac-Man will point straight north. In fact, the "x" Blue is really aiming for would be drawn beyond the north end of the playing field (about where the "8" in the high score is). When this happens, treat the target as being at the extreme edge of the playing field. At any rate, Blue will head north. For hypothetical purposes, imagine what would happen if Red was situated where Pinky currently is when Blue reaches the SW corner. Now the line puts the "x" at a spot west of Pac-Man, Blue goest west, and Pac-Man very soon finds himself a very tasty morsel on Inky's dinner plate!
Orange: As often happens, he's the weirdo of the bunch. At the NE corner of his island, he's in "near" mode. Yipes! Panic! Head for the corner of safety! (Go S.) But then when he reaches the next turn at the SE corner, he's removed enough to be in "far" mode. Loop back around toward Pac-Man (orbiting the small island is more direct than going around the sideways "T" island to orange's east). At the NW corner of the island, he's still "far," so he attempts to reduce the greater horizontal separation between himself and Pac in preference to the smaller vertical separation (i.e. he goes E instead of N here). But then he's back at the NE corner in "near" mode again. Yipes! Panic! Etc.
Note that this "hold" will not work if there are still scatter modes left on the level, or if blue is not closely following red. If you set it up wrong, blue will invariably be the one that "breaks out" of his orbit and comes over to kill you. Try it!
I believe the game will not allow the ghosts to go up the tunnels immediately above the monster pen and above where Pac-Man starts out even if the AI would otherwise direct the ghosts there. It's one of the easiest ways to shake Blinky if he's too close on your tail.
I apologize for the length of this post, but I couldn't think of how to put it more concisely. In my opinion, the ghost AI was a key to this game's incredible success. Small sections of code (often 50 bytes or less) lead to complex phenomena that take paragraphs to describe and have players attributing it to the "personalities" of the monsters. It's what vintage gaming is all about.
Those of you who have really analyzed the assembly code, you rock! If you've spotted errors in my analysis (I'm going more off playing experience than a solid understanding of Z-80 code), by all means put me in my place.
Hope this helps-
"Guzuta"
Edited by Otoboke, Mon May 21, 2007 7:38 PM.