Skip to content
GAME ARCHITECTS AI

Stories

How the Pac-Man ghosts think: the 4 rules

The Pac-Man ghosts seem to coordinate their attack. In fact, each one follows a single rule, and none of them looks at the others, with one exception.

By Published 7 min read

Pixel art illustration: at night, a man seen from behind and a small robot beside him look at an old arcade machine; on the screen, a blue maze with dots, a round yellow hero in the center and four ghosts, red, pink, light blue and orange, near the corners, with dotted golden lines crossing the maze between the ghosts, the hero and the corners. Image generated by artificial intelligence.

SUMMARY FOR WHEN YOU'RE SHORT ON TIME · 2 min

The Pac-Man ghosts don't think: each one aims at a spot in the maze and, at every intersection, turns toward the side closest to that spot. Red aims at Pac-Man, pink aims ahead of him, blue uses red's position and orange runs off when it gets close. Together, the four rules look like a team.

  • Pac-Man was released in Japan on May 22, 1980, by Namco, designed by Toru Iwatani, who did not code: he designed the rules and someone else wrote the code.
  • Iwatani said in 1986 that the hardest part was the movement of the four ghosts, because he didn't want them chasing the hero in single file.
  • Each ghost aims at a small square of the maze and, at every intersection, picks the path closest to that spot in a straight line, never turning back on its own.
  • Red aims at Pac-Man himself; pink aims four squares ahead of him; blue uses Pac-Man's position and red's; orange chases from afar and goes back to its corner when it gets within eight squares.
  • The attacks come in waves: in the first level, the ghosts scatter to the corners for 7 seconds and chase for 20, four times, and after that they only chase.
  • Pink's rule has a programming error: when Pac-Man faces up, the target also moves four squares to the left.
  • According to Wikipedia, Guinness recognized Pac-Man as the most successful coin-operated arcade game, with 293,822 machines installed.

Your first step: Think of an enemy in a game you know and write, in one sentence, the rule it follows, the way the red ghost's rule is written: it goes straight to where you are.

How do the Pac-Man ghosts decide where to go?

Each ghost picks a target, a small square of the maze, and moves toward it. The maze is divided into squares of 8 by 8 screen pixels, and the only thing that changes from one ghost to another is how it picks that target1.

The path to the target is the same for all four. Whenever it nears an intersection, the ghost looks at the exits and takes the one closest to the target in a straight line. It only thinks one step ahead, so it sometimes picks the longer way around1.

There are two restrictions. A ghost never turns back on its own. And when two exits are the same distance away, the order of preference is up, then left, then down1.

What is each ghost's rule?

One per ghost, and it fits in a sentence. The English names are Blinky, Pinky, Inky and Clyde; the Japanese nicknames, which appear in the game itself in Japan, describe better what each one does1.

GhostJapanese nicknameWhere it aims when chasing
Blinky, redOikake, "chaser"The square where Pac-Man is
Pinky, pinkMachibuse, "ambusher"Four squares ahead of Pac-Man
Inky, light blueKimagure, "whimsical"A spot calculated from Pac-Man and from red
Clyde, orangeOtoboke, "the one who plays dumb"Pac-Man, when far away; its own corner, when close

Red goes straight to where you are. That's why it almost always comes right behind Pac-Man. At two points in each level, as fewer dots remain, it gets 5% faster and stops giving you a break1.

Pink doesn't even aim at you: it aims four squares ahead of your mouth, to cut you off. Good players use this. If you head toward it, the target ends up behind pink itself, and it turns at the first exit1.

Blue is the only one that looks at another ghost. Its rule takes the spot two squares ahead of Pac-Man, draws a line from red to that spot and doubles its length. When red is far away, blue seems to wander; when red is close, blue shows up too1.

Orange chases just like red while it is more than eight squares away. When it gets closer than that, it switches its target to the bottom-left corner and leaves. The effect is a ghost that comes, gives up and comes back1.

Why did Iwatani make four different ghosts?

So the ghosts wouldn't chase the hero in single file. Toru Iwatani, the creator of Pac-Man at Namco, said in 1986 that the hardest part of the game was the algorithm for the four ghosts. An algorithm is the recipe of steps the computer follows. According to him, it was "the heart of the game"2.

He wanted each ghost to have its own way of moving, because four chasers in single file would make the game tiresome and flat, in his words. In the same interview, he describes red going straight after Pac-Man and another ghost aiming a few dots ahead of his mouth, almost "sandwiching" him2.

Iwatani also said he was not a programmer. He designed the rules and the parts of the game, and other people wrote the code. According to him, about five people worked on the game, which took a year and five months from idea to stores2. Wikipedia mentions Iwatani plus nine other people, and says work began in early 19793. The game came out in Japan on May 22, 1980, under the name Puck Man3.

Why do the ghosts attack and then scatter?

Because Iwatani felt that being surrounded all the time would be too stressful for the player. He created the attack in waves: the ghosts attack, retreat, regroup and attack again2.

In the game, this is a clock. In the first level, the ghosts spend 7 seconds each heading to their own corner of the maze, then 20 seconds chasing. This repeats, with the last two retreats lasting 5 seconds, and after the fourth wave they only chase1. In the following levels, the retreats get shorter and almost disappear1.

Every time the mode changes, the ghosts all turn around at once. It's the only time they do that, and it works as a warning for the player: the retreat has started, or it has ended1.

What changes when Pac-Man eats the big pellet?

The ghosts turn dark blue, move more slowly and stop having a target: at every intersection, they choose the turn almost at random. This is when Pac-Man does the hunting1. Iwatani described this twist as the chance for the hero to be the hunter as well as the hunted2.

An eaten ghost doesn't disappear. It goes back to the little house in the middle of the maze and then returns to the hunt. And the fright time shrinks with each level, until it disappears entirely from level 19 on1.

Do the Pac-Man ghosts have any bugs?

They have a famous one. When Pac-Man faces up, pink's calculation doesn't aim four squares above him: it aims four up and four to the left. Blue has the same deviation, by two squares1.

Programmer Don Hodges studied the original code and concluded that, in his opinion, it is a programming error in the way the game stores the "up" direction4. Hodges even wrote a corrected version of that code and warned that, with the fix, some routes players had memorized no longer work as before4.

Why do the ghosts' rules make Pac-Man so gripping?

Because you can learn each ghost, and whoever learns them escapes better (our take). Chad Birch, who explained these rules in 2010 based on Jamey Pittman's study, says he was able to avoid the ghosts much more easily after understanding them1.

The rules are short, but together they look like a team: one comes from behind, another cuts in front, a third closes the trap when the first one is near. Nobody planned anything. The trap comes from the four rules meeting1.

By the numbers

DataValueSource
Release in JapanMay 22, 1980Wikipedia3
Time from idea to storesAbout a year and five monthsIwatani, 19862; Wikipedia3
People on the projectAbout five, according to Iwatani; Iwatani plus nine, according to WikipediaIwatani, 19862; Wikipedia3
Ghosts4, each with a targeting ruleGameInternals, 12/02/20101
Dots per level240 small and 4 bigGameInternals1
Waves in the first level7 s of retreat and 20 s of attack, twice; then 5 s and 20 s; then 5 s and endless attackGameInternals1
Distance at which orange gives up8 squaresGameInternals1
Level at which the big pellet stops frighteningFrom 19 onGameInternals1
Arcade machines installed293,822, a Guinness recordWikipedia3

What the story of the ghosts shows, and what it doesn't

It shows that an enemy's behavior can be a single sentence, and that four well-chosen sentences look like intelligence (our take). It also shows that the person who decided those sentences was not the one doing the coding.

The other side

Pac-Man was made without AI, in 1979 and 1980, by a team at a game company, with a programmer and an engineer. Iwatani didn't code, but he had worked at Namco since 1977 and made games for a living. Calling the ghosts' rule "artificial intelligence" is a habit of the field: it is a fixed rule, written by hand, that looks one step ahead. And the detailed rules here come from fans who studied the game and its code, not from a Namco document; the Japanese nicknames, on the other hand, do appear in the game itself.

And what does AI do in this part today?

This part is not about Pac-Man, which was made without AI. It's about the work.

In 1980, each ghost rule needed someone who knew how to write the code. Today, people who don't code can describe the game in English and the AI writes the commands, which got the name vibe coding. That doesn't make the work easy: testing whether the enemy turned out fun, fixing and deciding are still up to you.

Knowing the names of things helps. Game makers call this enemy behavior, and asking for "an enemy that aims a little ahead of the player, to cut them off" is much clearer than asking for "a smart enemy" (our take). What the AI doesn't do is choose who hunts and how: that idea still belongs to whoever creates. If you want to start with something the right size, see what your first game should be, what the AI does and what stays with you and who created Tetris, another game born from a single rule.

Related questions

What are the names of the Pac-Man ghosts?

Blinky (red), Pinky (pink), Inky (light blue) and Clyde (orange). In Japan, the nicknames describe how each one behaves: chaser, ambusher, whimsical and the one who plays dumb.

Do the Pac-Man ghosts have artificial intelligence?

In game language, yes: any rule that moves a computer-controlled character is called AI. But it is a short, fixed rule, written by hand in 1980, that looks only one step ahead. It has nothing to do with the AIs that talk with you today.

Why does the orange ghost run away?

Because its rule changes with distance. Far from Pac-Man, it chases just like red; within eight squares, it switches its target to the bottom-left corner and leaves.

What happens when Pac-Man eats the big pellet?

The ghosts turn dark blue, move more slowly and choose each turn almost at random. During that time Pac-Man can eat them, and an eaten ghost goes back to the little house in the middle before returning to the hunt.

Do the Pac-Man ghosts communicate with each other?

No. Each one calculates its own target alone. The only link is that blue's rule uses red's position, which is why blue tends to show up when red is close.

Who created Pac-Man?

Toru Iwatani, at Namco. He said in 1986 that he was not a programmer: he designed the rules and the parts of the game, and other people wrote the code. The game took about a year and five months, from idea to stores.

Can I use rules like these in my game?

Yes, and that is how many enemies still work today: one short rule per enemy. When you ask an AI for a game, describing each enemy's rule this clearly helps the AI build what you imagined, but testing and tweaking are still up to you.

Sources

  1. Chad Birch, GameInternals, "Understanding Pac-Man Ghost Behavior" (12/02/2010; Internet Archive copy). Accessed October 25, 2026.
  2. Susan Lammers, "Programmers at Work" (1986), interview with Toru Iwatani (reproduction). Accessed October 25, 2026.
  3. Wikipedia, "Pac-Man". Accessed October 25, 2026.
  4. Don Hodges, "Pac-Man's Ghost Behaviour Analyzed and Fixed" (12/30/2008). Accessed October 25, 2026.

Was this article helpful?

Once a week, what changed in making games with AI

Every Tuesday, a 3 to 5 minute read: the news that changes something for people who want to make a game, one reader question answered, and the new articles. Unsubscribe anytime with one click.

By signing up, you agree to the privacy policy.

Found a mistake? Let us know. We fix it and log the correction on the page. Report a mistake