• Home
  • Blog
  • How Pac-Man Ghost AI Works The Classic Chase Algorithms
pac man ghost ai

How Pac-Man Ghost AI Works The Classic Chase Algorithms

The 1980s saw the start of Pac-Man, a game that changed the maze-chase genre. It’s not just about eating dots. It’s about the revolutionary AI that made the ghosts memorable.

Designer Toru Iwatani’s team had to work with just 2KB of memory. They made four unique ghosts with what they had. Every bit of memory was used wisely.

Underneath the colourful maze, a clever system works. Each ghost—Blinky, Pinky, Inky, and Clyde—has its own rules. Together, they create a perfect hunt.

This journey looks at the heart of the game, starting with Blinky’s chase. We’ll see how simple rules made a game that’s lasted for years.

Table of Contents

The Premise of Pac-Man: A Simple Maze, Complex Pursuit

Pac-Man’s maze is more than a game board; it’s a place where simple rules meet complex strategies. The goal seems easy: guide a yellow circle through a maze, eating dots while avoiding four ghosts. But, this simplicity hides a complex system of artificial intelligence.

The maze has few hiding spots. Its paths are straightforward. This design forces Pac-Man to face his pursuers head-on. The real challenge is the ghosts’ behaviour. They work together, each with their own role, creating a clever hunt.

“They are a team of hunters with different specialisations.”

— Toru Iwatani, Pac-Man Creator, 1986

This mix of teamwork and unpredictability is the game’s brilliance. Each ghost follows rules, yet together they create complex strategies. It’s a lesson in how simple code can lead to endless challenges.

The Four Ghosts: Personalities and Colours

The ghosts are not just enemies. Each has a name, colour, and personality that guides its actions. Knowing them is key to winning the game.

Blinky (Red) – The Shadow: Blinky is always chasing Pac-Man. His direct pursuit keeps the player on the move. He sets the pace and keeps the pressure on.

Pinky (Pink) – The Speedy: Pinky is sneaky. She aims for a spot ahead of Pac-Man, trying to cut him off. Her Pinky ambush tactic is a classic move.

Inky (Cyan) – The Bashful: Inky is unpredictable. His movements are based on Pac-Man’s and Blinky’s positions. This Inky vector calculation makes him hard to predict.

Clyde (Orange) – The Pokey: Clyde chases Pac-Man until he gets too close. Then, he becomes timid. This makes him an opportunistic ghost.

The ghosts work together, each with their own role. Blinky chases, Pinky ambushes, Inky confuses, and Clyde harasses. Their colours and personalities help players understand their strategies. This makes the ghost AI feel alive and strategic.

The Engine Room: Pac-Man’s Four Game States

The ghosts in Pac-Man follow a strict cycle of four states. This system makes them move together, making the game harder. The game’s success depends on understanding these states well.

The scatter chase cycle is key. Most of the game, ghosts switch between Scatter and Chase modes every 27 seconds. This pattern creates moments of pressure and relief, essential for strategy. When Pac-Man eats a certain number of pellets, the ghosts go into permanent Chase Mode, increasing the challenge.

Scatter Mode: The Brief Respite

Scatter Mode gives players a short break. In this time, each ghost goes to a specific corner of the maze. Blinky goes to the top-right, Pinky to the top-left, Inky to the bottom-right, and Clyde to the bottom-left.

This break lets Pac-Man move more freely and collect pellets. It’s a chance to plan and make progress. But, it’s short, keeping the player alert.

Chase Mode: The Core Challenge

Chase Mode is the game’s main challenge. Here, each ghost’s unique strategy is used. Blinky chases directly, Pinky ambushes, Inky uses complex plans, and Clyde changes based on distance.

This is when the real challenge starts. The ghosts work together, using their strategies to catch Pac-Man. Knowing how each ghost behaves in Chase Mode is key to survival and high scores.

Frightened and Eaten: The Power Pellet Dynamics

Eating a Power Pellet puts the ghosts in frightened mode. They turn blue, move slowly, and change direction. The time they stay vulnerable gets shorter, and they move slower as the game goes on.

If Pac-Man eats a ghost in this state, it becomes ‘Eaten’. It quickly returns to the ghost house. When it comes out, it goes back to Scatter or Chase mode. This gives players a temporary advantage, which skilled players use to clear the board.

Decoding the Pac-Man Ghost AI

To understand the ghosts’ behaviour, we need to know about target tile calculation and pathfinding logic. The game’s simple look hides a complex system. This system makes the game both challenging and predictable.

Every ghost moves based on rules that run 60 times a second. These rules use Pac-Man’s position and direction. This creates a chase that seems smart and yet follows a pattern.

The Target Tile: The Heart of the Algorithm

Each ghost is always chasing a specific spot in the maze. This spot is its target tile. How they find this tile is what makes them different.

Blinky, Pinky, Inky, and Clyde have their own ways of finding Pac-Man. Some might chase him right away, while others look ahead. This makes each ghost unique.

The game sees the maze as a grid of tiles. A ghost’s target is a set of (x, y) coordinates in this grid. These coordinates change fast, making the chase seem continuous and thoughtful.

Pathfinding: The Simplistic Genius

Once a target tile is set, the ghost must find its way. This is where pathfinding logic shines. The system is simple, despite the old arcade board’s limitations.

At every turn, the ghost checks its options. It looks at all paths, except the one it just took. For each path, it measures how close it is to the next tile and the target tile.

The ghost picks the path that gets it closer to the target. This simple rule, applied over and over, creates the complex group dynamics we love. It shows that smart AI in games doesn’t need to be complicated.

The genius is in the emergence. This simple rule, applied constantly with different targets, produces the complex and challenging group dynamics players know so well. It proves that effective artificial intelligence in games doesn’t require overwhelming complexity, just clever design.

Blinky: The Relentless Shadow

Blinky, the red ghost, is Pac-Man’s main enemy. He uses a simple chase algorithm. Unlike other ghosts, Blinky’s goal is just to catch Pac-Man fast.

Direct Pursuit: Targeting Pac-Man’s Current Tile

Blinky’s AI is simple. He always finds Pac-Man’s current spot in the maze. His aim is to get there as quickly as possible.

He uses direct pursuit to chase Pac-Man. The game updates their positions every frame. Blinky then picks the shortest path to Pac-Man.

This makes Blinky a constant threat. He’s always moving straight towards Pac-Man. His path shows the core chase idea by Toru Iwatani and his team.

Blinky direct pursuit Pac-Man ghost AI

Ghost Name Primary Target Behaviour Type Player Perception
Blinky (Shadow) Pac-Man’s current tile Direct aggression Predictable, relentless pressure
Pinky (Speedy) Four tiles ahead of Pac-Man Ambush Strategic cutting-off
Inky (Bashful) Vector based on Pac-Man and Blinky Erratic, unpredictable Unreliable, confusing
Clyde (Pokey) Pac-Man (when far) or scatter corner Opportunistic Random, less threatening

Elroy Mode: The Famous Speed-Up

Blinky’s threat grows with Elroy mode. This makes the game harder as you play better. It starts when Pac-Man eats a certain number of dots.

At first, Cruise Elroy mode starts when Pac-Man eats 75% of the dots. Blinky gets 5% faster. If Pac-Man eats 90% of the dots, the game gets even faster.

This idea by Toru Iwatani‘s team makes each level a race against time. You can’t just play slow. The Cruise Elroy mode requires quick thinking and precise moves.

Elroy mode turns Blinky into a deadline. It’s a great example of making the game harder as you get better. This keeps players tense for years.

Pinky: The Ambushing Speedy

Pinky is clever because she targets where Pac-Man is going, not where he is. This makes her a unique threat. She aims to cut off escape routes, not just follow Pac-Man. Her nickname, ‘Speedy’, shows her forward-thinking approach.

Four Tiles Ahead: The Classic Ambush

Pinky’s algorithm is simple yet effective. She aims four spaces ahead of Pac-Man, based on his direction. If Pac-Man is moving right, Pinky targets four tiles to the right of him.

This design makes players think ahead. Every turn could be a trap. The beauty of Pinky’s deterministic AI is its consistency. Skilled players can learn and anticipate her moves.

But, when combined with other ghosts, it becomes a complex challenge. Pinky’s ambush is most effective in long corridors. This gives her a clear path to intercept Pac-Man.

The table below shows how Pinky targets Pac-Man in different directions. It highlights the designers’ straightforward logic.

Pac-Man’s Direction Intended Target Calculation Primary Tactical Effect
Right Pac-Man’s position + 4 tiles right Blocks exits from long horizontal passages
Left Pac-Man’s position + 4 tiles left Anticipates retreats and cuts off reverse routes
Down Pac-Man’s position + 4 tiles down Intercepts movement through vertical shafts
Up Pac-Man’s position + 4 tiles up Seeks to trap player in upper dead-ends

The Up-Direction Bug: A Quirk of Programming

Pinky’s logic has a famous flaw that became a game charm. When Pac-Man moves up, a bug causes Pinky’s target to be wrong. This is due to an arithmetic overflow error in the 8-bit hardware.

This glitch makes Pinky’s ambush point unpredictable. She may appear from any maze quadrant. This bug shows how technical limits can shape gameplay in unexpected ways.

The up-direction bug is not random but a predictable result of system constraints. It shows the deterministic nature of the ghost system, where every action has a predictable reaction.

This quirk is well-documented in analyses of the original code. For example, the detailed analysis of Pac-Man ghost AI. It highlights the importance of understanding hardware limits in designing behaviour systems. For players, it added mystery to mastering the game, proving that ‘bugs’ can be part of a timeless game AI programming legacy.

Inky: The Unpredictable Bashful

Inky’s algorithm is unique, using a two-vector calculation. This makes his path hard to guess. Unlike Blinky, who is direct, and Pinky, who ambushes, Inky’s moves seem random.

His name, “Bashful,” is ironic. He seems shy but can pop up unexpectedly. This unpredictability makes him interesting to study in early game AI.

The Two-Vector Calculation: Blinky as a Pivot

Inky doesn’t aim for Pac-Man’s current spot or a point ahead. Instead, he uses a geometric process. This process involves both Pac-Man and Blinky, as explained in the Pac-Man Dossier by Don Hodges.

First, the game finds a tile two spaces ahead of Pac-Man. This is like Pinky’s first step but is just a middle point.

Then, Blinky’s position is used as a pivot. An imaginary vector is drawn from Blinky to the tile two ahead of Pac-Man. This vector is then doubled in length.

The doubled vector’s end is Inky’s target tile. His path is simply to reach that tile in the maze.

Inky’s path is linked to Blinky’s position. If Blinky is far, Inky’s target can be far too. If Blinky is near, the target is closer. This calculation happens every frame, making it dynamic.

Creating Erratic Behaviour

Inky’s unpredictability comes from Blinky’s changing position. Blinky’s moves make Inky’s target tile shift in ways not directly related to Pac-Man’s path. This leads to several unique behaviours.

Inky often moves diagonally, flanking Pac-Man. He can seem lost before suddenly focusing when the vector calculation works out. This unpredictable movement can trap players in corners or block their escape routes.

Inky’s actions are more about strategic interference than relentless pursuit. With Blinky’s direct pressure and Pinky’s ambush, Inky’s erratic paths make a complete hunting party. He keeps players from falling into a simple pattern.

The table below shows how each ghost targets Pac-Man differently, highlighting Inky’s unique approach:

Ghost Primary Target Key Logic Behavioural Trait
Blinky (Red) Pac-Man’s current tile Direct coordinate pursuit Aggressive & relentless
Pinky (Pink) 4 tiles ahead of Pac-Man Forward projection Ambushing & interceptive
Inky (Cyan) Vector from Blinky to a point 2 ahead of Pac-Man, doubled Two-vector calculation Erratic & unpredictable
Clyde (Orange) Pac-Man’s tile (if far) or Scatter corner (if close) Proximity-based switch Opportunistic & cautious

Understanding Inky’s algorithm shows the depth of Pac-Man’s design. It’s not just about four chasers. It’s about a system where each ghost’s logic affects the others. Inky’s link to Blinky creates a dynamic maze ecosystem, as seen in the Pac-Man Dossier.

Clyde: The Opportunistic Pokey

Clyde is different from the other ghosts in Pac-Man. He doesn’t follow a set plan. Instead, he acts based on how close he is to Pac-Man.

While Blinky chases and Pinky ambushes, Clyde is unpredictable. You can’t always know what he’ll do next. This makes him a unique challenge for players.

The Proximity Switch: Chase or Scatter?

Clyde’s actions are based on how far he is from Pac-Man. The game checks this in tiles. If he’s more than eight tiles away, he chases Pac-Man.

But if Pac-Man gets within eight tiles, Clyde changes his plan. He stops chasing and goes for the maze’s bottom-left corner instead.

The Role of the Wild Card

Clyde’s switch makes him seem unpredictable. His sudden changes can help Pac-Man escape from other ghosts. This can be a lifesaver when Blinky and Pinky are closing in.

But, Clyde can also surprise Pac-Man by suddenly chasing him. This keeps the ghosts’ attacks unpredictable. It adds a strategic layer to the game.

For speedrun experts, like Billy Mitchell, understanding Clyde is essential. They must always watch his distance. They might lure him in to scatter him, or keep him close to stop him from chasing. Getting Clyde’s timing right is critical to outsmarting the ghosts.

From Concept to Code: Implementing the Algorithms

The journey from a simple idea to the Z80 assembly code for the ghosts is key in arcade game history. It was a big challenge to turn the ghosts’ unique personalities into a strict system. The solution was a blend of rules and randomness, making the ghosts seem smart.

Pseudocode Breakdown: The Logic of a Single Ghost

Each ghost has its own way of choosing targets, but they all follow the same basic steps. This shared logic happens every time a ghost hits a new tile in the maze.

Here’s a simple overview of what happens:

  • Check Current State: See if the ghost is in Scatter, Chase, Frightened, or Eaten mode. This tells it what to do next.
  • Calculate Target Tile: Based on its state and personality, figure out the target tile’s coordinates on the maze.
  • Evaluate Valid Moves: Look at all possible directions from the current tile, avoiding reversals (except in Frightened or Eaten states).
  • Choose Direction: For each valid path, find the shortest distance to the target tile. The ghost picks the path with the shortest distance.
  • Handle Ties: If several paths are equally short, use a priority order (usually Up, Left, Down, Right) to decide.

This simple loop, run many times a second, makes the ghosts chase and scatter in complex ways. It uses just simple math.

Hardware Constraints: Programming Within Limits

The ghost AI’s true brilliance is in how it was made to work within the original hardware. The whole game, including the ghost AI, had to fit into just 2 kilobytes of ROM. This tiny space forced the programmers to find clever shortcuts.

They used fixed seeds and lookup tables to fake randomness, avoiding complex math. They also used simple distance calculations for pathfinding. Every byte of code was checked for efficiency.

Pac-Man AI programming constraints

The sequel, Ms. Pac-Man, showed a new approach. Its AI had more variables and pseudo-random elements, making the ghosts less predictable. A big change was the introduction of variable ghost speeds, adding a new challenge. This marked a big step forward in chase algorithms for sequels.

The table below shows the main differences between the AI of the two classic games:

Feature Original Pac-Man AI Ms. Pac-Man AI
Core Logic Deterministic with fixed patterns Increased pseudo-random elements
Ghost Speed Mostly constant (except Elroy mode) Variable speeds introduced
Memory Footprint Extremely optimised for 2KB ROM More complex, utilising expanded hardware
Player Strategy Reliable pattern memorisation Required more adaptive reaction
Randomisation Fixed seed tables More dynamic random factors

Today, games often use similar ghost behaviours but with new methods. For example, they might use vector or trigonometry for smoother movements. These methods give the same feeling of engaging, yet predictable, pursuers. They show the lasting impact of the original idea.

The Legacy of a Digital Hunt: Impact and Modern Relevance

Pac-Man’s digital hunt has had a big impact, shaping computer science and competitive gaming. Its ghost AI showed how simple code can lead to deep gameplay. This idea is studied and used in game design today.

Shaping Game Design Philosophy

Pac-Man’s enemy design taught us a lot. It showed that predictable rules can lead to complex gameplay. The ghosts followed simple rules, but together they created exciting moments.

This idea is seen in games like Among Us. The Imposter’s known moves add a social twist to the game. Pac-Man also introduced the idea of distinct enemy roles. This is seen in games like Dead by Daylight, where each killer has their own strategy.

The game’s use of state-based behaviour is also influential. This method is used in many games to control the difficulty and player emotions. It’s a key part of survival horror and action games.

This influence is not just in games but also in education. The game’s efficient AI design is studied in schools. It’s seen as a model for constrained, effective AI design.

Patterns, Speedrunning, and Mastery

The game’s AI made it possible for players to master it. By memorising patterns, players could solve the maze. This created a competitive scene.

Speedrunning communities take this to the next level. They use their knowledge of the game to perform perfectly. It’s not just about quick reflexes but also understanding the game’s systems.

Modern games like Pac-Man Championship Edition pay homage to the original. They keep the classic ghost personalities but add new features. The most advanced games use neural network adaptations to create new AI behaviours.

This shows how Pac-Man’s design is timeless. The legacy of Pac-Man AI supports both classic mastery and modern neural network adaptations. Its principles are truly lasting.

Conclusion

Pac-Man’s AI is a masterpiece of simplicity. It uses four rules in a state machine to create a chase that seems smart and can be learned. Blinky chases directly, Pinky ambushes, and Inky adds a bit of surprise.

Clyde is the game’s wild card. He switches between chasing and scattering based on his distance from Pac-Man. This makes the game hard to memorise, pushing players to think and adapt. Despite being made in the 1980s, its focus on fun and simplicity is timeless.

Toru Iwatani’s team made a game that’s both predictable and surprising. This mix has led to a lot of study, from speedrunning to modern game design. Pac-Man’s ghosts teach us about creating engaging AI with simple yet clever rules.

FAQ

What are the names and personalities of the four ghosts in Pac-Man?

The ghosts are Blinky (red, Shadow), Pinky (pink, Speedy), Inky (cyan, Bashful), and Clyde (orange, Pokey). Each ghost has a unique colour and nickname. These names reflect their different chasing behaviours in the game.

How do the ghosts decide which way to turn at an intersection?

At intersections, each ghost picks a target tile based on its mode and personality. It then chooses the closest direction to that tile. This simple rule creates the complex patterns seen in the game.

What is Blinky’s “Elroy Mode”?

Elroy Mode is a special feature for Blinky. When Pac-Man eats a certain number of dots, Blinky gets faster. This makes the game harder as it progresses, showing the game’s clever challenge.

Why does Pinky sometimes behave strangely when Pac-Man is facing up?

Pinky has a bug when Pac-Man is facing up. Instead of going four tiles up, Pinky goes up and left. This creates a surprise ambush point.

Why is Inky’s behaviour considered the most unpredictable?

Inky’s path changes because Blinky moves. This makes Inky’s movements seem unpredictable. He often surprises Pac-Man by cutting across the maze.

What determines whether Clyde chases Pac-Man or runs away?

Clyde’s behaviour changes based on his distance from Pac-Man. If he’s far, he chases. If close, he flees to a corner. This makes him unpredictable.

How were such sophisticated behaviours programmed with such limited hardware?

The ghost AI was coded in just 2KB of ROM. The developers used clever shortcuts and simple rules. This made the system a masterpiece of programming.

Can you memorise patterns to beat the Pac-Man ghosts?

Yes, you can. The ghost AI is predictable. Players can learn patterns to beat levels. This is key in Pac-Man speedrunning.

What is the difference between Chase Mode and Scatter Mode?

In Chase Mode, ghosts chase Pac-Man. In Scatter Mode, they go to fixed corners. This gives the player a break and shapes the game’s pace.

How did Pac-Man’s ghost AI influence modern video game design?

Pac-Man’s AI set the stage for modern game design. It showed how to create complex enemies with simple rules. This approach is seen in many games today.

Releated Posts

Ghost Write AI Using AI for Anonymous Content Creation

The digital world is changing fast, thanks to advanced machine learning. Tools like GPT-4 can write content quickly,…

ByByTom Sheen Jan 23, 2026

Ghost Face AI Voice How to Create the Horror Movie Voice

The Scream franchise’s chilling figure is a horror icon. It’s known for its stark mask and eerie voice.…

ByByTom Sheen Jan 21, 2026

AI Ghosts The Concept of Digital Afterlife and Memories

For thousands of years, humans have wanted to be remembered. We built monuments and wrote poems. Now, we…

ByByTom Sheen Jan 5, 2026

AI Ghost Rider Autonomous Motorcycle Technology Explained

While self-driving cars get all the attention, a autonomous motorcycle is a real engineering wonder. It’s called the…

ByByTom Sheen Jan 1, 2026

Leave a Reply

Your email address will not be published. Required fields are marked *