Pacman AI – flee and seek

In this post I explore the Netlogo PacMan game, focusing on interaction between player (pacman) and ghosts.

Pacman is a classic 1980’s video game which demonstrates attract and flee AI. The objective of the player is to eat dots and progress to the next level, whilst optionally eating ‘power up’ pills to eat or keep the opponent ghosts at bay or eat them for extra points. Random ‘bonus’ items also appear to increase the score. As the game progresses the layout progresses between 5 maps increasing in complexity and the speed of the ghosts increases making navigating and consuming the dots more challenging.

pac-man / ghost encounter without pill = died

As can be seen, where pacman encounters a ghost without a power pill, he is killed. The results in the level restarting, minus any already consumed pills. The ghost return to their center square home and pacman to his standard ‘spawning’ point on the maze map.

new pacman, ghosts return, dots still in place

The ghosts to start with exhibit a random path, but as soon as the line of sight between pacman and ghost on the maze is established, the ghosts exhibit the AI behaviour of ‘seek’

ghosts see pacman and are attracted to him giving chase !

to choose-heading ;; Ghosts Procedure
let dirs clear-headings
let new-dirs remove opposite heading dirs
let pacman-dir false

if length dirs = 1
[ set heading item 0 dirs ]
if length dirs = 2
[ ifelse see-pacman item 0 dirs
[ set pacman-dir item 0 dirs ]
[ ifelse see-pacman item 1 dirs
[ set pacman-dir item 1 dirs ]
[ set heading one-of new-dirs ]

gHOSTS ROUTINE TO SEEK PACMAN

This can result in an untimely ending to pacman if his escape around the maze is not done from the pursuing ghosts. A strategy is to allow the ghosts to see pacman, but in range of a power pill, whereby pacman will then be able to consume the ghosts and score more points. The ghosts exhibit the AI ‘flee’ behaviour.

power pill consumed ghosts flee !

The interaction of player and pacman is straightforward enough, press a key and move, with some animation. Edge detection is used to determine the walls between pacman and the maze.

Conclusion

In this classic 80’s game we can observe classic seek and flee behaviours of the AI. The AI also seems to loose interest in chasing pacman if the ghost is outwitted long enough. Whilst a simple game, its no doubt that the hunt and chase of ghosts still makes compelling game play even in todays modern era of far more graphically superior games.

Leave a Reply

Your email address will not be published. Required fields are marked *