On the Subject of Ghost Movement

Who knew controlling ghosts was so complicated?

The module has four buttons representing each of the ghosts, and a submit button representing Pac-Man in the center, each button having a screen. The displays show the following information: their position in the maze (letter being the column from left to right, number being from top to bottom), and the direction they’re facing in the form of an arrow. Clicking each button changes the arrow on the button. Point each arrow in the direction each ghost will go in next (determined by the rules below) and then press the Pac-Man button to solve the module. If any arrow is pointed in a wrong direction, a strike will occur, with incorrect directions in red. Holding the Pac-Man button will reset the directions of the ghosts to their initial state.

Finding Target Tiles for each ghost

Blinky: The target tile is exactly where Pac-Man is located.

Pinky: The target tile is exactly four tiles in front of Pac-Man, with the exception of when Pac-Man is facing up, in that case the target tile is four tiles up and four tiles to the left of Pac-Man.

Inky: Find the tile two tiles in front of Pac-Man (and like Pinky, if Pac-Man is facing up, go two tiles up and two tiles to the left), this will be point X. Then, find the tile where Blinky is located. Rotate the point where Blinky is located 180° about point X. This is Inky’s target tile.

Clyde: If Clyde is more than eight tiles away from Pac-Man, the target is exactly where Pac-Man is located. Otherwise, The target is at tile 4531 (Marked with an orange C in the reference maze below).

If a target tile (that isn’t Clyde’s) or point X is in the red region (all tiles not shown in the reference maze are in the red region), change the target to the non-red tile which is the closest using Manhattan distance, the smallest number of orthogonal (up, left, down, right) steps needed to move between the two points.

Finding a direction to move depending on a target tile

Remove all directions which are:
-Within a wall.
-Opposite to where the ghost is facing.

Of any remaining directions, the tiles which you can move to that’s closer to it linearly (using X2 + Y2, where X is the number of tiles left or right from the ghost and Y being the number of tiles up or down from the ghost) is the one the ghost should move to.

If the remaining directions are the same distance away, use the priority order below, the leftmost one being the highest priority.

Up, Left, Down, Right

If a ghost is at L11, O11, L23 or O23 the ghost cannot move upwards
(The four positions are marked with a white X in the reference maze below).


The MapTiles 8 spaces away from Pac-Man