shaunew/Pac-Man — Issue #14: add attract mode - pacman's AI
Author: shaunew
Created: 2012-01-30 10:34:19+00:00
State: open

from an email exchange with Jamey Pittman:
---------------
As for how the original game guides Pac-Man in demo/attract mode, it works like this:

Pac-Man operates in one of two possible pathfinding modes during the demo game. Let's call the first one "Run Away From Pinky" mode. In this mode, the code measures the distance from the pink ghost to Pac-Man and then doubles it to find his final target (see attached .jpg for an example). Imagine drawing a line from Pinky to Pac-Man and then continuing the line out that far again beyond Pac-Man. Whatever tile that extended line ends up in is Pac-Man's target tile. This results in Pac-Man making turns that keep him as far away from Pinky as possible more often than not.

The second mode of behavior does just the opposite and we'll call it "Get Pinky" mode. This mode is much simpler and uses Pinky's current tile as Pac-Man's target.

Which mode of targeting Pac-Man uses is based on the state of one ghost in particular. Oddly enough, the ghost state evaluated by the code is NOT Pinky but Blinky (red)! Anytime Blinky is not dead (i.e., eyes going back home) or frightened, Pac-Man uses the "Run Away From Pinky" mode for targeting. Whenever Blinky is either frightened or dead, however, Pac-Man switches to "Get Pinky" mode until Blinky returns to normal. Watch the attract/demo mode a few times with these two modes of behavior in mind and you'll see it working just as described. It's a very simple scheme but effective.
---------------