Pac-ManSpecs

Ghost pathfinding

BlinkyPinkyInkyClyde

Roaming. Blinky starts outside. Pinky, Inky and Clyde leave at 2, 4 and 6 seconds. At each tile center, a ghost randomly picks a legal turn, avoiding reversal unless forced or powered.

Returning home. A captured ghost finishes its current segment. Breadth-first search checks up, then left, then down, then right. Each tile crossing costs one step, including the tunnel.

Example. Blinky returns from (13,11) to (14,14) in four steps. Two routes tie. Down is checked before right.

Blinky starts at column 13, row 11, moves down three tiles through the door, then right to home. The dashed alternative goes right and then down three.
Tile 0 is the start. The numbered path reaches home at tile 4. The dashed route is equally short.