Pac-Man (HTML5 / Google Doodle): Complete Ghost AI Targeting Algorithms, Cornering, and 256 Pattern Guide

Master the exact deterministic AI algorithms of Blinky, Pinky, Inky, and Clyde, corner pre-turning, and high-score routing in HTML5 Pac-Man.

Pac-Man (created by Toru Iwatani for Namco in 1980, and famously preserved in HTML5 via the legendary 30th Anniversary Google Doodle) is not a game of random chance. Every single ghost in the maze is governed by a deterministic, mathematically precise targeting algorithm.

Understanding how each ghost calculates its target tile allows you to manipulate their movements, group them for quadruple eat streaks, and navigate high-speed fruit stages.


1. The Four Ghost AI Targeting Algorithms

Every ghost has two alternating modes: Scatter (retreats to its home corner) and Chase (targets Pac-Man based on specific mathematical rules):

┌────────────────────────────────────────────────────────┐
│ Ghost Personalities & Math Formulas                   │
├────────────────────────────────────────────────────────┤
│ • Blinky (Red - "Shadow"): Directly targets Pac-Man's  │
│   exact current coordinate tile (Direct Pursuer).      │
│                                                        │
│ • Pinky (Pink - "Speedy"): Targets 4 tiles ahead of    │
│   Pac-Man in his current facing vector (Ambush/Pincer).│
│                                                        │
│ • Inky (Cyan - "Bashful"): Targets a complex vector    │
│   calculated by doubling the distance between Blinky   │
│   and 2 tiles ahead of Pac-Man (Unpredictable Flank).  │
│                                                        │
│ • Clyde (Orange - "Pokey"): If >8 tiles from Pac-Man,  │
│   targets Pac-Man. If <8 tiles, retreats to bottom-    │
│   left corner (Cowardly Cycle).                        │
└────────────────────────────────────────────────────────┘

2. Cornering Pre-Turns: Gaining Distance

Pac-Man moves faster through turns than the ghosts:

  • The Pre-Turn Input: If you press an arrow key before reaching an intersection, Pac-Man hugs the inner corner with sub-pixel precision, gaining approximately 1 tile of lead distance over trailing ghosts with every turn.

3. Power Pellet Ghost Multipliers

When consuming a flashing Power Pellet, ghosts turn dark blue and reverse direction:

  • 1st Ghost: 200 Points
  • 2nd Ghost: 400 Points
  • 3rd Ghost: 800 Points
  • 4th Ghost: 1,600 Points Always group at least 3 to 4 ghosts in your wake before touching a Power Pellet to maximize round point yield.

Share this guide
DV

About the Author: Devin Vance

Devin Vance writes technical guides and performance benchmarks at TabGamer, covering browser graphics, WebGL flags, low-spec laptop optimization, and retro WebAssembly emulation.