Behavior of Pac-Man
A ghost always maintains its current direction until it reaches an intersection, at which point it can turn left or right. Periodically, the ghosts will reverse direction and head for the corners of the maze (commonly referred to as "scatter mode"), before reverting to their normal behavior. In an interview, Iwatani stated that he had designed each ghost with its own distinct personality in order to keep the game from becoming impossibly difficult or boring to play. The behaviors of each ghost have been exactly determined by reverse-engineering the game.
Despite the seemingly random nature of some of the ghosts, their movements are strictly deterministic, enabling experienced players to devise precise sequences of movements for each level (termed "patterns") that allow them to complete the levels without ever being caught. A later revision of the game code altered the ghosts' behavior, but new patterns were soon developed for that behavior as well. Players have also learned how to exploit other flaws in the ghosts' behavior, including finding places where they can hide indefinitely without moving, and a code bug occasionally allows Pac-Man to pass through a non-blue ghost unharmed. Several patterns have been developed to exploit this bug. The bug arises from the fact that the game logic performs collision detection based on ghost / Pac-Man occupancy of grid squares, where the grid squares are large relative to the size of the characters. A character occupies (for collision detection purposes) only one grid square ("tile") at at time, despite its graphic depiction overflowing to another tile. If a ghost and Pac-Man switch tiles with each other simultaneously (which is not a rare phenomenon, because the tiles granularity is large), a collision isn't detected.
Source: Pac-Man - Wikipedia, the free encyclopedia