← All interactive demos

How the Ghosts Chase You — Interactive Demo

This is the calculation from the video "How do Pac-Man’s ghosts chase you?", ready to run. Each ghost picks one "target square". Every time it reaches the centre of a square, it turns toward whichever open path makes the straight-line distance to the target shortest (it never turns back, and on a tie the order is up → left → down → right). The maze and the visuals are our own, not the original game screen.

1. Try to escape (arrow keys / buttons below)

Time escaped 0.0 s / —

2. Target rules for the 4 ghosts

Scatter time (scatter 7 s, chase 20 s, …)
Task: compare how many seconds you can escape when all 4 ghosts use the same rule and when they are all different. Which ghost's rule makes escaping hardest when you change it?

3. Automatic escape from 20 starting points (measured the same way as in the video)

The escaping square runs automatically from 20 places in the maze (it moves away from the nearest ghost along the maze). We count the seconds until it is caught (the middle value of the 20 runs) and how long, before it was caught, there were ghosts both in front of and behind it (within 6 squares).
RulesWavesUntil caught (median)Ghosts in front and behind

The rules: Current square = the square the player is on. 4 ahead = 4 squares ahead in the direction the player is facing. Double the line = draw a line from ghost 1 (red) to the square 2 ahead of the player, and double its length. 8 squares = if more than 8 squares from the player, the current square; if closer, its own corner (outside the maze). During scatter time, each of the 4 ghosts targets a different corner outside the maze (it can never reach it, so it circles near the corner). When chase ⇔ scatter switches, all ghosts reverse direction at once.
These patterns are taken from sources that analysed the 1980 game "Pac-Man" (Jamey Pittman, "The Pac-Man Dossier"; Chad Birch, "Understanding Pac-Man Ghost Behavior") and run in our own maze (they are not an official explanation from the company that made the game). Speeds: the square moves 6 squares a second, the ghosts 5.4 squares a second. Calculated in fixed steps of 1/60 s.
Sources and production: same as the video description (AI was used to make the diagrams and script. No game footage or characters are used).