如果吃豆人向左移动，Pinky的目标贴图就是向左距离吃豆人当前贴图四个贴图的地方。如果吃豆人向右移动，Pinky的目标就是相应地改成右边。如果吃豆人向下移动，那么粉鬼的目标誻 下向距离吃豆人四个贴图的地方。如果吃豆人向上移动，Pinky的目标就是向上和向左距离吃豆人四张贴图的地方。之所以产生这个有趣的结果是因为计算Pinky朝吃豆人移动的逻辑代码有一个小错误。这部分代码对于其他三种情况来说是运行正常的，但当吃豆人向上移动时，就会触发一个误把向左移动计算在内的漏洞（Inky的逻辑也存在这个问题）。Don Hodges的网站上有一篇好文章从代码的角度详尽地分析了这个漏洞，还提供了源代码和解决方案。
The Pac-Man Dossior
by Jamey Pittman
Meet The Ghosts
“First, you’ve got to learn how to control the monsters. See how the red, pink and blue are grouped together? It’s easier to control two monsters than four monsters.”—Chris Ayra, champion Pac-Man player
In the last chapter, we learned how a ghost follows a target tile through the maze. Now we will take a closer look at Blinky, Pinky, Inky, and Clyde to better understand why they behave so differently when in chase mode. They all share the same pathfinding logic for chasing a target tile, so how is it each one behaves differently when following Pac-Man? The answer is delightfully simple: Pac-Man’s tile is not always the target. Every ghost has a distinct method for calculating its target tile in chase mode, resulting in their unique personalities. Some of the ghosts use Pac-Man’s actual tile as the target; others only use it as an intermediate step to find another tile. Sometimes a ghost is targeting a tile that has absolutely nothing to do with Pac-Man at all! Regardless of where a ghost’s target tile is at the time, Pac-Man will still be killed if he gets in that ghost’s way.
Rumor has it Toru Iwatani and his team spent months doing nothing but tweaking and refining the ghost A.I. routines before releasing Pac-Man to the world. Their efforts show in the final product: Itawani’s team created the illusion of complex pathfinding by using very simple logic and very little code.
Blinky: The red ghost’s character is aptly described as that of a shadow and is best-known as “Blinky”. In Japan, his character is represented by the word oikake, which means “to run down or pursue”. Blinky seems to always be the first of the ghosts to track Pac-Man down in the maze. He is by far the most aggressive of the four and will doggedly pursue Pac-Man once behind him.
Of all the ghosts’ targeting schemes for chase mode, Blinky’s is the most simple and direct, using Pac-Man’s current tile as his target. In the pictures above, we can see Blinky’s target tile is the same as Pac-Man’s currently occupied tile. Targeting Pac-Man directly in this way results in a very determined and tenacious ghost who is tough to shake when he’s right behind you.
All ghosts move at the same rate of speed when a level begins, but Blinky will increase his rate of speed twice each round based on the number of dots remaining in the maze (if Pac-Man dies this is not necessarily true – more on this in a moment). While in this accelerated state, Blinky is commonly called “Cruise Elroy”, yet no one seems to know where this custom was originated or what it means. On the first level, for example, Blinky becomes Elroy when there are 20 dots remaining in the maze, accelerating to be at least as fast as Pac-Man. More importantly, his scatter mode behavior is also modified at this time to keep targeting Pac-Man’s current tile in lieu of his typical fixed target tile for any remaining scatter periods in the level (he will still reverse direction when entering/exiting a scatter period). This results in Elroy continuing to chase Pac-Man while the other three ghosts head for their corners as normal. As if that weren’t bad enough, when only 10 dots remain, Elroy speeds up again to the point where he is now moving faster than Pac-Man. As the levels progress, Blinky will turn into Elroy with more dots remaining in the maze than in previous rounds. Refer to Table A.1 in the appendices for dot counts and speeds for both Elroy changes, per level.
Determining when Blinky turns into Elroy can become more complicated if Pac-Man is killed. The ghosts and Pac-Man are reset to their starting positions whenever a life is lost and, when play continues, Blinky’s “Cruise Elroy” abilities are temporarily suspended until the orange ghost (Clyde) stops bouncing up and down inside the ghost house and moves toward the door to exit. Until this happens, Blinky’s speed and scatter behavior will remain normal regardless of the number of dots remaining in the maze. Once this temporary restriction is lifted, however, Blinky will resume changing his behavior based on the dot count.
Pinky: Nicknamed “Pinky”, the pink ghost’s character is described as one who is speedy. In Japan, he is characterized as machibuse, meaning “to perform an ambush”, perhaps because Pinky always seems to be able to get ahead of you and cut you off when you least expect it. He always moves at the same speed as Inky and Clyde, however, which suggests speedy is a poor translation of the more appropriate machibuse. Pinky and Blinky often seem to be working in concert to box Pac-Man in, leaving him with nowhere to run.
In chase mode, Pinky behaves as he does because he does not target Pac-Man’s tile directly. Instead, he selects an offset four tiles away from Pac-Man in the direction Pac-Man is currently moving (with one exception). The pictures below illustrate the four possible offsets Pinky will use to determine his target tile based on Pac-Man’s orientation:
If Pac-Man is moving left, Pinky’s target tile will be four game tiles to the left of Pac-Man’s current tile. If Pac-Man is moving right, Pinky’s tile will be four tiles to the right. If Pac-Man is moving down, Pinky’s target is four tiles below. Finally, if Pac-Man is moving up, Pinky’s target tile will be four tiles up and four tiles to the left. This interesting outcome is due to a subtle error in the logic code that calculates Pinky’s offset from Pac-Man. This piece of code works properly for the other three cases but, when Pac-Man is moving upwards, triggers an overflow bug that mistakenly includes a left offset equal in distance to the expected up offset (we will see this same issue in Inky’s logic later). Don Hodges’ website has an excellent article giving a thorough, code-level analysis of this bug, including the source code and a proposed fix—click here to go there now.
Pinky is the easiest ghost to exert control over thanks to his targeting scheme. By changing direction, you can dictate where Pinky will turn next when he is nearby (see above picture). If you are facing off closely with Pinky, he will turn before he reaches you if he can. This happens due to the fact Pac-Man has come close enough to Pinky for Pinky’s target tile to now be behind him. In the picture above, Pinky chooses to turn up at the intersection because moving left would have taken him further away from his target tile. The longest-lived example of this is the technique known as “head faking”. This is where the player shakes the joystick to cause Pac-Man to rapidly change direction back and forth, hopefully causing a ghost to change course in the process. As it turns out, the shaking is not necessary—one well-timed, quick reversal of direction towards Pinky just before he decides what to do at an upcoming intersection is all that is needed to get him off your tail.
Inky: The light-blue ghost is nicknamed “Inky” and his character is described as one who is bashful. In Japan, he is portrayed as kimagure, meaning “a fickle, moody, or uneven temper”. Perhaps not surprisingly, Inky is the least predictable of the ghosts. Sometimes he chases Pac-Man aggressively like Blinky; other times he jumps ahead of Pac-Man as Pinky would. He might even wander off like Clyde on occasion! In fact, Inky may be the most dangerous ghost of all due to his erratic behavior. Bashful is not a very good translation of kimagure, and misleads the player to assume Inky will shy away from Pac-Man when he gets close which is not always the case.
Inky uses the most complex targeting scheme of the four ghosts in chase mode. He needs Pac-Man’s current tile/orientation and Blinky’s current tile to calculate his final target. To determine Inky’s target, we must first establish an intermediate offset two tiles in front of Pac-Man in the direction he is moving (represented by the tile bracketed in green above). Now imagine drawing a vector from the center of the red ghost’s current tile to the center of the offset tile, then double the vector length by extending it out just as far again beyond the offset tile. The tile this new, extendend vector points to is Inky’s actual target as shown above.
For the same reasons already discussed in Pinky’s case, an overflow error occurs with the intermediate offset tile generated for Inky’s calculation when Pac-Man is moving up resulting in an offset tile that is two tiles above and two tiles to the left (see above picture). The other three orientations (left, right, down) produce the expected result of an offset two tiles in front of Pac-Man in the direction he is moving.
Inky’s targeting logic will keep him away from Pac-Man when Blinky is far away from Pac-Man, but as Blinky draws closer, so will Inky’s target tile. This explains why Inky’s behavior seems more variable as Pac-Man moves away from Blinky. Like Pinky, Inky’s course can often be altered by Pac-Man changing direction or “head-faking”. How much or how little effect this will have on Inky’s decisions is directly related to where Blinky is at the time.
Clyde: The orange ghost is nicknamed “Clyde” and is characterized as one who is pokey. In Japan, his character is described as otoboke, meaning “pretending ignorance”, and his nickname is “Guzuta”, meaning “one who lags behind”. In reality, Clyde moves at the same speed as Inky and Pinky so his character description is a bit misleading. Clyde is the last ghost to leave the pen and tends to separate himself from the other ghosts by shying away from Pac-Man and doing his own thing when he isn’t patrolling his corner of the maze. Although not nearly as dangerous as the other three ghosts, his behavior can seem unpredictable at times and should still be considered a threat.
During chase mode, Clyde’s targeting logic changes based on his proximity to Pac-Man (represented by the green target tile above). He first calculates the Euclidean distance between his tile and Pac-Man’s tile. If the distance between them is eight tiles or more, Clyde targets Pac-Man directly just as Blinky does. If the distance between them is less than eight tiles, however, Clyde switches his target to the tile he normally uses during scatter mode and heads for his corner until he gets far enough away to start targeting Pac-Man again. In the picture above, Clyde is stuck in an endless loop (as long as Pac-Man stays where he is) thanks to this scheme. While occupying any tile completely outside the dashed perimeter, Clyde’s target is Pac-Man. Upon entering the area, Clyde changes his mind and heads for his scatter target instead. Once he exits the perimeter, his target will change back to Pac-Man’s current tile again. The end result is Clyde circling around and around until Pac-Man moves elsewhere or a mode change occurs. Clyde is fairly easy to avoid once you understand his targeting scheme. Just remember: he is still dangerous if you manage to get in his way as he runs back to his corner or before he can reach an intersection to turn away from you.(source:home.comcast)