- random movement: not bad actually. In game AI this may work well enough. Of course, the ghosts will not really track down the pac-man but if you have many ghosts then sooner of later they would reach the pac-man (Brownian motion).
- minimize Euclidian distance: you compare your x,y with that of the target. If you can move towards the target you will. In our specific case this would not work well. The ghost is stuck on the other side of the wall. If the ghost would move left or right it would increase the distance.
- use an established AI algorithm such as A*. A* is quite powerful but aside of the problem that it is not that simple to implement it would not work well if you want to have the ghost work collaboratively.
A much simpler yet more powerful approach based on the notion of Antiobjects is called Collaborative Diffusion. In our pac-man example the antiobject of the pac-man is the maze itself. The maze becomes the computationally active part distributing AI into the environment. Imagine we give the pac-man an attribute called "p" for pac-man with a value of 1000. Now we have each background agent in the worksheet diffuse this value by looking at its 4 (up, down, right, left) neighbors, add up their p values and compute the average. Each background agent computes it p attribute as p = 0.25 * (p[up] + p[down] + p[left] + p[right])
To show you what these values are we plot that p value for all of the agents including the background agents and the pac-man itself and plot the value logarithmically. Notice the shape of the 3D plot and observe what happens as we move around the pac-man. The pac-man becomes a mountain peak.
<flvplayer width="480" height="320" autoplay="false" hidecontrols="false">Pac-man diffusion no walls.flv</flvplayer>
This would be a pretty boring Pac-man game. Let's add some walls to the game. The walls do not have a diffusion equation. When asked by their neighbors for a value of the p attribute they will return 0.
<flvplayer width="480" height="320" autoplay="false" hidecontrols="false">Pac-man diffusion walls.flv</flvplayer>
Now lets actually have the ghosts track the pac-man by climbing up the diffusion surface through Hill climbing. Observe the two ghosts closely:
<flvplayer width="480" height="320" autoplay="false" hidecontrols="false">Collaborative diffusion two agents.flv</flvplayer>
The fact that the two ghosts split up is not a coincidence. They collaborate with each other. You go this way and I go that way. The idea is called collaboration by goal obfuscation. The ghosts do not have a variable p. They act the same way as walls by pulling down the collaborative diffusion surface. How well can this simple idea really work? Watch five ghosts tracking down a pac-man. Notice, there is only one optimal solution for the ghosts to track down the pac-man.
<flvplayer width="480" height="320" autoplay="false" hidecontrols="false">Collaborative diffusion five agents.flv</flvplayer>
Incredibly, the 5 ghosts have no problem to find that one optimal solution. Imagine trying this any other way. For instance, you could have used an A* to have one ghost find the pac-man but how would you coordinate all the ghosts to make sure they go to all the different escape paths?
As described in Repenning (2006), collaborative diffusion can be used to create even more sophisticated interactions among agents. For example, in a soccer simulation, diffusions from the ball, from the two goals, and from players on the two teams can produce remarkable coordination among the movements of the simulated players.
This template project includes some a basic house layout, a couple of characters and some diffusions. Missing: The project does not include Hill climbing nor does it implement the Maslow hierarchy of needs.
- Repenning, A., Collaborative Diffusion: Programming Antiobjects. in OOPSLA 2006, ACM SIGPLAN International Conference on Object-Oriented Programming Systems, Languages, and Applications, (Portland, Oregon, 2006), ACM Press.
- Antiobjects slides including movies (Apple keynote format)