Pac-Man’s ghosts look as if they are hunting together. Blinky follows close behind, Pinky cuts in ahead, and the other two turn up where the player least wants them. None of them is thinking. Each ghost looks only at the next junction, and takes whichever turn leaves it closest to a single target square. The four ghosts differ mainly in how they pick that square, and that small difference is what makes four simple followers feel like a pack.
Toru Iwatani, who designed the game at Namco in 1980, said why. “Had the programming been such that the four ghosts constantly attacked Pac-Man’s present location according to the same algorithm, the ghosts would look like a string of beads,” he told Retro Gamer. “Where’s the thrill in that? So I introduced AI-type algorithms that had the ghosts coming at Pac-Man from all directions.” Asked in 1986 what had been the hardest part of making the game, he named “the algorithm for the four ghosts”.
Fast facts
- Game: Pac-Man (Namco, 1980), designed by Toru Iwatani.
- How a ghost moves: at each junction, the exit nearest its target square in a straight line. It never turns back of its own accord.
- The targets: Blinky aims at Pac-Man, Pinky four squares ahead of him, Inky at a point built from Pac-Man and Blinky, Clyde at Pac-Man until he gets within eight squares.
- The waves: four times a level the ghosts break off for their home corners, then return to the attack.
- Frightened: after a power pellet the ghosts turn by a pseudo-random number, which restarts from the same seed every level.
Why four ghosts
Iwatani told Edge in 1998 that the game began with eating, and the enemies and maze came next: “After that, I decided to add the element of four ghosts as enemies. Just moving around an open field would be too much freedom and no fun, so I set up a maze environment.” He did not think of them as scenery. “All of the ghosts have different AI algorithms that reflect their comical personalities. It’s sort of like asking whether Tom or Jerry is the star of the ‘Tom and Jerry’ cartoons.”
His own descriptions of the ghosts stayed the same for decades. In the 1986 interview the red ghost, Blinky, “did chase directly after Pac Man”, while the second “is positioned at a point a few dots in front of Pac Man’s mouth”, so that the two end up “almost ‘sandwiching’ him”. “The other ghosts move more at random,” he said. Retro Gamer’s 2010 account of what Iwatani “has in the past stated” is almost word for word the same.
How a ghost chooses a turn
Namco never published the rules. Players and programmers have since worked them out from the arcade program, most fully in Jamey Pittman’s The Pac-Man Dossier, and a C translation of the ROM by Michael Burkley shows the same routines line by line.
The maze is a grid of squares (tiles). As a ghost moves into a new tile it decides what to do at the next one. The routine at $2966 in the ROM tries each direction out of that tile in turn. It skips walls, and it skips the direction the ghost came from, so a ghost never reverses by choice. For each remaining exit it measures the distance from the neighbouring tile to the target tile, as the square of the horizontal gap plus the square of the vertical gap, and keeps the shortest. When two exits tie, the order of the test settles it: up first, then left, then down, then right.
That is all. There is no path-finding. A ghost does not know the shape of the maze, and it will happily take a turning that leads it the long way round, because the turning pointed in roughly the right direction. The behaviour players read as cunning comes entirely from where each ghost puts its target.
The four targets
When the ghosts are chasing, each sets its target this way:
| Ghost | Target square | What it looks like |
|---|---|---|
| Blinky (red) | The square Pac-Man is on | He follows close behind. |
| Pinky (pink) | Four squares ahead of Pac-Man, in the direction he is moving | She cuts him off, and with Blinky behind, the pair “sandwich” him. |
| Inky (cyan) | Take the square two ahead of Pac-Man, draw a line from Blinky to it, and double its length | Near Pac-Man when Blinky is close behind him; far away when Blinky is not. |
| Clyde (orange) | Pac-Man’s square while he is eight or more squares away; his home corner when he is closer | He charges in, then wanders off. |
Inky and Clyde are the two Iwatani described as moving “more at random”. In the program they are not random at all. Inky’s target swings about because it depends on where Blinky happens to be, and Clyde’s switches whenever he crosses the eight-square line, which the program checks by comparing the squared distance with 64. Both are fixed rules whose results are hard to predict by eye. Wireframe summed up the effect in 2020: with “a few simple rules like these, Iwatani created the illusion of non-player characters whose moves could be immediately recognised if the player spent enough time with the game”.
Chase and scatter
The ghosts do not attack all the time. “When a human being is constantly under attack like this, he becomes discouraged,” Iwatani said in 1986, so the team “developed the wave-patterned attack-attack then disperse; as time goes by the ghosts regroup and attack again.” In the program this is a phase counter. In a scatter phase each ghost targets a fixed square beyond its own corner of the maze (Blinky top right, Pinky top left, Inky bottom right, Clyde bottom left), so the pack breaks up and circles. There are four scatter phases in a level, after which the ghosts chase for good. Iwatani said that “gradually the peaks and valleys in the curve of the wave become less pronounced so that the ghosts attack more frequently”, and Pittman’s measurements agree: the breaks get shorter on later levels.
Every change between chase and scatter forces all the ghosts to turn round on the spot, the only time they reverse. Pittman points out that the sudden about-turn is the visible sign that a phase has changed.
Blinky has one more rule. When only a few dots are left in the maze he speeds up, twice in a level, and from then on he ignores the scatter phases and keeps chasing. Players call this “Cruise Elroy”, a name whose origin, Pittman notes, no one seems to know.
The reversal
The power pellet turns the rules over. “By eating a power pellet, Pac transforms himself from being pursued to being the pursuer,” Iwatani told Edge. “This change in the flow of action makes the game much more dynamic.” It was a late addition: “The inspiration for the power pellet was the spinach in the TV cartoon Popeye. The power pellets didn’t exist in the planning stages at all — they emerged during the development stage as a feature for turning the game around.”
A frightened ghost has no target. It turns blue, reverses, and at each junction takes a direction chosen by a pseudo-random number. Pittman found that the generator restarts from the same seed at the start of every level, so even the frightened ghosts move the same way each time the player does the same thing.
A bug with a long life
There is a mistake in the code. When Pac-Man is moving up, the sum that finds the squares “ahead” of him also moves the point the same distance to the left. Pinky aims four squares up and four to the left; Inky’s two-square offset goes wrong in the same way. Wireframe noted in 2020 that it is “a glitch that players have been exploiting for the past four decades – even if they don’t necessarily realise the error that causes it.”
Patterns
Because the ghosts follow fixed rules and even their “random” moves repeat, the same moves by the player produce the same game. Players learned routes, called patterns, that cleared a maze without being caught. By February 1983 Electronic Games was explaining high scores by the two styles of play: some players “vary their ‘pattern’ strategies in some cases to maximize bonus points while, on the opposite side of the spectrum, other gamers base their tactics on avoidance, eating only those ghosts they happen to meet while in the energized state.” The same reply took it for granted that the screen “‘breaks down’ after 250 keys”, the level-256 failure described in the Pac-Man entry.
Chris Crawford, writing his book on game design in 1982, singled out the balance: the pursuers “are just slightly slower than the human player; their intelligence and number make up for this”, and the pace “makes it difficult for the player to fully analyze the positions of the five pieces in real time.”
The names
The ghosts’ names changed between markets. The Japanese release called them Akabei, Pinky, Aosuke and Guzuta. On the American attract screen each has a character and a nickname: Shadow “Blinky”, Speedy “Pinky”, Bashful “Inky” and Pokey “Clyde”. The names were on merchandise by mid-1982: Electronic Games reported Fleer’s sticker cards showing “Speedy, Bashful, Pokey, and Shadow (aka ‘Blinky’, ‘Pinky’, ‘Inky’ and ‘Clyde’)”, the two lists in a different order from the cabinet’s pairing.
Sources
- Retro Gamer Collection vol. 4, 2010, pp. 27–29, Craig Grannell, “The Making & Remaking of: Pac-Man”: the “string of beads”, Blinky and Pinky, the ghosts attacking in waves, the power pellet and Popeye, the Japanese names, the attract-screen roster.
- Susan Lammers, Programmers at Work (Microsoft Press, 1986), interview with Toru Iwatani: the ghosts as the hardest part, Blinky’s chase, the ghost “a few dots in front of Pac Man’s mouth”, “sandwiching”, “more at random”, the wave-patterned attack and why. Reproduced at https://www.oocities.org/siliconvalley/heights/5874/iwatani.htm (web, secondary).
- Edge issue 65, December 1998, pp. 69–70, “A Question of Character”, interview with Toru Iwatani: eating, the four ghosts and the maze, “different AI algorithms”, Tom and Jerry, the power pellet.
- Edge issue 8, May 1994, p. 60, Namco’s game history: Pac-Man, July 1980.
- Jamey Pittman, The Pac-Man Dossier, version 1.0.27, 2015 (web, secondary): how a ghost picks its turn and the tie-break order, the four targets, the scatter corners and four scatter periods, reversal on mode changes, frightened ghosts’ pseudo-random turns and the reset seed, Blinky’s speed-ups, the “up” bug. https://pacman.holenet.info/
- Michael Burkley, pacman-c, a C translation of the Pac-Man arcade ROM with the original disassembly as comments (GitHub, 2024, MIT licence) (web, secondary): the turn-choosing routine at
$2966, the distance calculation at$29EA, the four chase and scatter targets at$2730–$283A, Clyde’s comparison with 64, the frightened ghosts’ random direction routine, and Blinky’s scatter override. https://github.com/mburkley/pacman-c - Wireframe issue 40, June 2020, pp. 112–113, “Killer Feature: Pac-Man”: Blinky targeting the player, Inky using Pac-Man and Blinky, “a few simple rules”, and Pinky’s bug when Pac-Man faces up.
- Electronic Games vol. 1 no. 12, February 1983, p. 88, readers’ letters: pattern play and avoidance, the screen that “breaks down”.
- Electronic Games vol. 1 no. 5, July 1982, p. 10: Fleer’s Pac-Man stickers and the ghosts’ names.
- Chris Crawford, The Art of Computer Game Design (written 1982; electronic edition, Washington State University Vancouver, 1997), chapter 3, “Maze Games”: the pursuers “just slightly slower than the human player”.