On the Subject of Frightened Ghost Movement

“Why are you blue?”

This module attempts to simulate the behavior of ghosts in PAC-MAN when they are in a frightened state. In gameplay, this occurs when Pac-Man eats a power pellet. The four blue buttons display each ghost’s coordinate—always at an intersection—on the map and the direction it was traveling when it entered the intersection.

The buttons can be pressed to change the directions displayed. To solve the module, point the arrows in the direction each ghost will go next and then press the yellow button in the center of the module. Hold down the yellow button to reset the displayed arrows.

Generating the RNG Indices

  • To determine the starting directions, four RNG indices must be calculated, which respresent each ghost in reading order.
  • The first RNG index is equal to the bomb's serial number digits concatenated modulo 8192.
  • Generate three more indices by multiplying the previous index by 5 and adding 1, modulo 8192.

Ri = (5 × Ri-1 + 1) mod 8192

Obtaining the Starting Directions

  • Once the RNG indices are obtained, take each of them modulo 400 and index them into the ROM Table on the following page.
  • The numbers obtained from the ROM Table correspond to a direction as depicted to the right.

Obtaining the Final Directions

  • Locate each ghost on the map found on page 3.
  • If the ghost can move in the direction obtained from the ROM Table, it will move in that direction. Otherwise, rotate it clockwise until the ghost can move in that direction.
    • A ghost cannot move in a direction if there is a wall in that direction.
    • A ghost also cannot move in the direction opposite their current direction (which is displayed on each button).

ROM Table

This table is meant to represent the complete ROM data of PAC-MAN. In the actual game, the RNG index mod 8192 is used as a memory address into the game’s memory to obtain a single byte, of which only the rightmost two bits are used to obtain the starting direction. However, since some bytes occur more in the game’s memory than others, the distribution of these bits is uneven. This biased distribution is reflected in the below table—only with 400 memory addresses available instead of 8192.


Note: If a ghost is at an intersection marked with an X in the below map, the ghost cannot move up there.