Game Development Reference
In-Depth Information
FIGURe 3.7
Flocking birds
In games, we see similar effects. Over the years players have wondered if the ghosts
in Pac-Man are deliberately teaming up against the player and laying traps to catch
the player. In fact, the ghosts do not collaborate, and their collective behavior appears
to be much smarter than it actually is. The ghosts in Pac-Man are simple machines
that follow simple rules. The game alternates between two states: scatter and chase.
In the scatter state, the ghosts do not hunt the player, but each seeks out a different
corner of the maze. Most of the time, however, the game is in the chase state, when
the ghosts hunt the player. To hunt the player, the ghosts have to make a decision
at each intersection in the maze. The algorithm that is used chooses the direction
that brings the ghost closer to the player. It simply ignores any walls between the
ghost and the player. Their behavior is implemented just a little differently for every
ghost: Blinky (the red ghost) tries to go the player's current position; Pinky (the
pink ghost) tries to go to a position four tiles ahead of the player; Inky (the blue
ghost) combines the player's position and the position of Blinky to determine where
to go; and finally Clyde (the orange ghost) chases the player when he is far away
but tries to get to lower-left corner of the maze when he gets close. Together, the
effects of the movements seem surprisingly smart: Blinky will follow the player
while Pinky and Inky try to get ahead of the player, and Clyde adds in some noise.
As a group, the ghosts are fairly effective hunters even with no knowledge of where
the others are actually located. This combination of simple behaviors gives players
the impression they are being hunted collaboratively, when they simply have com-
plementary strategies.
T IP For an extended
discussion of the
ghost's behavior in
Pac-Man, see http://
gameinternals.com/
post/2072558330/
understanding-pacman-
ghost-behavior.
 
Search WWH ::




Custom Search