Arcade & AI Architecture • 12 min read • Published 2026-11-01

Pac-Man Ghost AI: State Machines and Tile Targeting Algorithms

An architectural breakdown of classic maze AI. How Blinky, Pinky, Inky, and Clyde execute distinct targeting math across Scatter, Chase, and Frightened modes.

Pac-Man Ghost AI: State Machines and Tile Targeting Algorithms

Toru Iwatani’s 1980 masterpiece Pac-Man is widely celebrated for its cheerful aesthetics, but beneath its neon maze lies one of the most brilliant breakthroughs in the history of artificial intelligence. If all four enemy ghosts had simply tracked the player using standard shortest-path algorithms, the game would have been unplayable: the ghosts would have coalesced into a single lethal pack, cornering and killing the player within seconds. Instead, Iwatani engineered four distinct, deterministic Tile-Targeting State Machines, giving each ghost a unique behavioral personality through simple geometric formulas.

In our retro arcade catalog, titles like Retro Maze Man and Retro Pac Maze Escape honor this foundational AI architecture. By deconstructing the mathematical targeting rules of Blinky, Pinky, Inky, and Clyde, players can anticipate enemy vectors, manipulate ghost paths, and master high-level maze routing.


1. Grid Mechanics: The Intersection Decision Engine

The maze is modeled as a discrete $28 \times 36$ tile grid. To understand ghost navigation, one must understand how a ghost selects its direction:

               THE INTERSECTION LOOKAHEAD DECISION
                    Candidate: NORTH (Euclidean d1)
                                ▲
                                │
   Candidate: WEST ◄──── [ INTERSECTION ] ────► Candidate: EAST
    (Euclidean d2)              │                (Euclidean d3)
                                │ (Illegal: Cannot reverse SOUTH!)

The Three Movement Constraints:

  1. Zero Reversal Invariant: A ghost cannot reverse its direction ($180^\circ$ turn) during normal navigation. If a ghost enters an intersection moving East, it can only continue East, turn North, or turn South. It cannot turn back West.
  2. One-Tile Lookahead Calculation: A ghost decides which turn to take one full tile before it actually enters an intersection.
  3. Euclidean Distance Minimization: When choosing among available adjacent tiles, the ghost calculates the straight-line Euclidean distance from each candidate tile to its current Target Tile ($T_x, T_y$): $$d = \sqrt{(X_{\text{candidate}} - T_x)^2 + (Y_{\text{candidate}} - T_y)^2}$$ The ghost selects the candidate tile that strictly minimizes $d$. If two options produce identical distances, the engine resolves ties using strict directional priority: Up > Left > Down > Right.

2. Deconstructing the Four Ghost Personalities

Each of the four ghosts possesses a distinct targeting equation, producing emergent psychological behaviors from elementary arithmetic:

                               THE GHOST TARGETING MATRIX
  ┌─────────────────────────────────────────────────────────────────────────────┐
  │ 1. BLINKY (Red / "Shadow")    ──► Target: Pac-Man's exact current tile (X, Y)│
  ├─────────────────────────────────────────────────────────────────────────────┤
  │ 2. PINKY (Pink / "Speedy")    ──► Target: 4 tiles ahead of Pac-Man's heading │
  ├─────────────────────────────────────────────────────────────────────────────┤
  │ 3. INKY (Cyan / "Bashful")    ──► Target: Doubled vector from Blinky to      │
  │                                           intermediate tile ahead of Pac-Man │
  ├─────────────────────────────────────────────────────────────────────────────┤
  │ 4. CLYDE (Orange / "Pokey")   ──► Target: If d > 8 tiles, target Pac-Man;   │
  │                                           If d <= 8 tiles, flee to corner!   │
  └─────────────────────────────────────────────────────────────────────────────┘

1. Blinky (Red - Oikake / The Chaser)

Blinky is the primary relentless pursuer. His targeting formula is direct tracking: $$T_{\text{Blinky}} = (X_{\text{PacMan}}, Y_{\text{PacMan}})$$

  • Cruise Elroy Mechanic: When the remaining dots in the maze drop below specific thresholds (e.g., 20 dots, then 10 dots), Blinky permanently speeds up, eventually moving faster than Pac-Man even when eating dots.

2. Pinky (Pink - Machibuse / The Ambusher)

Pinky does not chase Pac-Man; she sets an ambush. Her target tile is located 4 tiles ahead of Pac-Man’s current directional heading: $$T_{\text{Pinky}} = (X_p + 4 \cdot \vec{v}_x, Y_p + 4 \cdot \vec{v}_y)$$

  • The Up-Overflow Bug: Due to a famous 16-bit register offset in the original Z80 assembly code, when Pac-Man faces UP ($\vec{v} = (0, -1)$), the engine accidentally offsets Pinky’s target 4 tiles up and 4 tiles left, creating a unique diagonal ambush vector.

3. Inky (Cyan - Kimagure / The Flanker)

Inky is the most complex algorithmic agent. His target tile depends on both Pac-Man’s heading and Blinky’s physical position:

  1. Identify the intermediate reference tile $R$, located 2 tiles ahead of Pac-Man.
  2. Draw a mathematical vector $\vec{V}$ from Blinky’s current tile to $R$: $$\vec{V} = R - \text{Pos}_{\text{Blinky}}$$
  3. Double this vector and project it from Blinky’s position: $$T_{\text{Inky}} = \text{Pos}_{\text{Blinky}} + 2 \cdot \vec{V}$$ This mathematical relationship means that if Blinky is close to Pac-Man, Inky attacks aggressively; if Blinky is far away, Inky’s target swings wildly to the opposite side of the maze, creating terrifying pincer movements.

4. Clyde (Orange - Otoboke / The Feigner)

Clyde alternates between aggression and cowardice based on proximity:

  • Calculate Euclidean distance $d$ between Clyde and Pac-Man.
  • If $d > 8$ tiles: Clyde targets Pac-Man directly ($T_{\text{Clyde}} = \text{Pos}_{\text{PacMan}}$).
  • If $d \le 8$ tiles: Clyde panics, abandoning the chase to retreat to his home corner in the bottom-left of the maze ($T_{\text{Clyde}} = (0, 31)$).
                      CLYDE'S DISTANCE THRESHOLD LOGIC
              [Pac-Man]
                  │
          Distance > 8 Tiles? ───► YES: Aggressive Chase (Acts like Blinky)
                  │
                  ▼ NO (d <= 8)
         Cowardly Retreat! ──────► Retreats to Bottom-Left Corner

3. The Global Mode State Machine: Scatter, Chase, and Frightened

The entire ghost fleet operates under a synchronized global timer that cycles between three operational modes:

    [START] ──► [SCATTER 1 (7s)] ──► [CHASE 1 (20s)] ──► [SCATTER 2 (7s)] ──► [CHASE 2 (20s)] ──► ...
                     │                     │                     │
                     ▼                     ▼                     ▼
              Retreat to Corner      Hunt by Rules         Retreat to Corner
              (Breathing Room)       (Pincer Attack)       (Breathing Room)

1. Scatter Mode (Periodic Retreat)

During Scatter Mode, all ghosts cease hunting Pac-Man. Their target tiles are reassigned to fixed coordinates outside the four corners of the maze. The ghosts disperse to their respective corners, looping in harmless circles for 5 to 7 seconds. This grants the player predictable windows to clear open corridors.

2. Chase Mode (Active Hunting)

Ghosts re-engage their individual targeting formulas, hunting Pac-Man across the maze. In standard levels, Scatter and Chase alternate four times before the engine locks permanently into endless Chase Mode.

3. Frightened Mode (Power Pellet Eaten)

When Pac-Man eats an energizer, all ghosts instantly reverse direction ($180^\circ$ turn), turn deep blue, and slow down. Their target tiles are chosen using a pseudo-random number generator at every intersection, making their movements erratically defensive.


4. Technical Comparison: Arcade AI Systems and Pathfinding

The following matrix compares artificial intelligence architectures and spatial decision mechanics across classic browser-based arcade titles:

Game TitleEnemy AI ArchitecturePathfinding MethodPredictability FactorPrimary Evasion TacticPortal Title
Retro Maze ManMulti-Agent State MachineTile-Targeting Euclidean Distance100% DeterministicCorner Looping & Mode SynchronizationRetro Maze Man
Pac Maze EscapeAsymmetric Pincer SwarmOffset Vector ProjectionHighLuring Blinky into Scatter PhaseRetro Pac Maze Escape
Snake ClassicSelf-Avoidance GraphGreedy Breadth-First ExpansionLowHamiltonian Cycle PackingSnake Classic Retro
Sokoban WarehouseStatic Obstacle CollisionA* Forward Crate PathfindingAbsoluteDeadlock Pre-CalculationSokoban Warehouse Puzzle
Clumsy BirdProcedural Obstacle SpawnerFixed-Velocity Parabolic BarrierDeterministicVertical Tap RhythmClumsy Bird

5. Exploiting Ghost AI for High-Score Mastery

To dominate maze levels in Retro Maze Man:

  1. Manipulate Pinky by Shifting Heading: Because Pinky targets 4 tiles ahead of your heading, briefly facing toward a wall shifts Pinky’s ambush target into a dead-end, buying you safe passage across central corridors.
  2. Never Flee in Clyde’s Direction: If you run toward Clyde, you will cross his 8-tile radius threshold. Clyde will suddenly turn around and flee directly ahead of you into his bottom-left corner, cornering you against Blinky.
  3. Cross-Train Topological Navigation: Hone your discrete grid navigation across Snake Classic Retro to build rapid cornering instincts.

Frequently Asked Questions

Why do the ghosts reverse direction when entering Scatter Mode?

The $180^\circ$ direction reversal is the engine’s visual signal that a mode change has occurred. Because ghosts are mathematically forbidden from reversing under normal conditions, the game engine artificially forces a $180^\circ$ turn whenever Scatter, Chase, or Frightened modes trigger. Skilled players watch for this sudden reversal to confirm that Scatter mode has begun, signaling it is safe to traverse the center of the board.

What is the “Split Screen” bug at Level 256 in classic Pac-Man?

At Level 256, the 8-bit assembly subroutine that draws the fruit counter overflows: it attempts to draw 256 fruit symbols, exceeding the screen memory limits and corrupting the right half of the maze with garbage characters. This effectively terminates play, making Level 256 the legendary unbeatable “Kill Screen” of arcade history.

Is it possible to find a spot in the maze where ghosts can never find you?

Yes. There is a famous “Safe Spot” located directly to the right and above the ghost house. If Pac-Man enters this coordinate while no ghost is directly observing him and faces UP, the mathematical targeting formulas of all four ghosts will continuously cycle around him without ever designating that specific coordinate as a target, allowing the player to remain safe indefinitely.

Featured Games Mentioned in This Guide

Play Retro Pac Maze Escape online Arcade

Retro Pac Maze Escape

Chamber maze chase arcade. Devour dots throughout twisting corridors while dodging spectral phantoms and claiming power fruit bonus points.

SW

Lead Game Designer

The ShishaWare Games editorial team consists of passionate web engineers, computational puzzle analysts, and classic gaming enthusiasts dedicated to curating high-performance, ad-free web experiences.