Collaborative Diffusion

From Scalable Game Design wiki
Jump to navigation Jump to search

When you need to find a way through a complex space such as a maze or if you need to have multiple agent collaborating with each other, e.g., for a soccer game then Collaborative Diffusion is likely to be a good solution. Imagine a game such as Pac-Man where you have a user controlled Pac-Man and AI controlled ghosts tracking the pac-man. Look at the following situation. How would you program the ghost to track down the pac-man?

Ghost tracks pac-man.png

Some ideas:

  • 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.

Basic Diffusion

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.

<embedvideo service="youtube" dimensions="[856|856x513|x513]"></embedvideo>

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.

<embedvideo service="youtube" dimensions="[856|856x513|x513]"></embedvideo>

Simple Collaboration

Now lets actually have the ghosts track the pac-man by climbing up the diffusion surface through Hill climbing. Observe the two ghosts closely:

<embedvideo service="youtube" dimensions="[856|856x513|x513]"></embedvideo>

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.

<embedvideo service="youtube" dimensions="[856|856x513|x513]"></embedvideo>

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.

Template project

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.


Games/Simulations that use this pattern