We experimented with different variations of the Pac-Man and ghost algorithms to generate movement on an irregular "playing field," the Number Garden.

Created: September 28th, 2014

0
Of the most famous arcade games, Pac-Man features a remarkably elegant algorithm for movement. We took this hard-coded process and transformed it into a living game with emergent elements. Giving each player the role of Pac-Man or ghost, we simulated multiple games on an irregular playing field, the Number Garden.

We chose the Number Garden to help with our algorithm, as it it provides a gridded surface on to which we can move in 4 directions at any one time. We also hoped that the calculated, but ultimately emergent nature of our algorithm would be enhanced by the numerical but random layout of the Number Garden floor.

0

Algorithm

0

Each of the players was given a specific algorithm based on the characters in Pac-Man:

Pac-Man: try to get from his starting position to the target position while avoiding the ghosts.

Blinky: Take the shortest path to Pac-Man

Inky: Take the shortest path to 4 tiles in front of Pac-Man

Clyde: Move about “randomly” (this will be discussed further below)

Pseudo-code for the movement algorithms:

0
Pac-Man.pos, target_pos, clyde_target = random_tiles
while game == in_play:
    case player of:
      Pac-Man: if ghost.distance <= 5:
                   move 1 tile away from ghost
               else:
                   move 1 tile toward target_pos
      Blinky:  move 1 tile toward Pac-Man.pos
      Inky:    move 1 tile toward (Pac-Man.pos + 4) // 4 tiles in front of Pac-Man
      Clyde:   if Clyde.pos == clyde_target:
                   clyde_target = (clyde_target + 1) % 10
               else:
                   move 1 tile toward clyde_target

    if Pac-Man.pos == ghost.pos:
        game = over // Pac-Man loses
    else if Pac-Man.pos == target_pos:
        game = over // Pac-Man wins
Click to Expand
0

Details of Clyde’s movement: Start on some random number. Let x be the tile he is standing on currently. If x < 9, then take the shortest path to the nearest tile with x+1. If x == 9, then take the shortest path to the nearest tile with a 0. Repeat until the game is over.

Over the course of 6 trials, we varied the starting and end positions for Pac-Man and the ghosts using a random number generator (the start and endpoints had to be on opposite sides of the field). In addition, we made slight modifications to the rules:

Trials 1-2: All ghosts and Pac-Man start at random numbered tiles.

Trials 3-4: All ghosts and Pac-Man start at random numbered tiles. In addition, Pac-Man is allowed to move from one edge of the field to the other (looping around, as in the actual game).

Trials 5-6: Pac-Man is allowed to loop around the playing field. All ghosts start in the center of the playing field, and leave the center after 5, 10, and 15 steps in the order of Clyde, Inky, and Blinky.

0

Outcome

0
0

The simple algorithm that each character had caused a different outcome to be played out each time. Our algorithm was also very vague in parts (e.g. "take the shortest path" does not give precise instructions on how to derive this shortest path) and this led to variances between the players, and between trials.

The algorithm felt mechanical at times, as the movement speed was fixed to tiles. In addition, the lack of obstacles led to a few straight-line chases, but this was reduced by the looping mechanic introduced in trial 3, as well as the curved shape of the Number Garden.

Overall, it was interesting to observe how a simple pre-programmed rule set could produce an elegant and emergent outcome.

x
Share this Project


About

We experimented with different variations of the Pac-Man and ghost algorithms to generate movement on an irregular "playing field," the Number Garden.