Ghost pathfinding
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.
