Feels like there are a lot of zombie themed games out there right now. But this isn’t a post about that trend, but rather about the issue of having a “train” of agents after a single object.

Let me outline the issue for you. Imagine you have N number of agents, all seeking a particular resource. Now the problem occurs when all of those N agents try and attain the same object at the exact same time. What you get is basically a “train” of agents all moving towards the given object. This gets even worse if the object is moving and is faster than the agents trying to obtain it. You get what old MMO players used to call a “train” of AI characters.

YouTube Preview Image

Above is a video of agents with a simple “find object in radius, if object within radius try and get to it” behavior. Notice it definitely looks like a train? In the case of zombies (which you are seeing here) it really isn’t that much of a problem as you expect zombies to be a bit dumb. But this really isn’t acceptable in the general case.

In real life, you would never see this because humans would spot that someone else is likely to get the particular object and would decide to therefore try and attain something else, or they would decide to compete for the resource in some way (perhaps by blocking the progress of the other agents?).

Clearly we need to have some logic to alleviate this problem.

Solition 1 – Use agent proximity

One answer is to do what humans do and simply consider all other agents and their relative proximity to the object and determine who is more likely to get it. But this would need to be computed per-agent for each other agent. These kind of complex calculations are relatively cheap to do on modern machines, but too many of them soon add up to major slowdown. Clearly as the number of agents increases the cost of calculating this sort of data quickly gets out of control.

Solution 2 – Use “smart objects”

Another answer, which seems more logical, is to have all agents express their wish to acquire the resource and have the resource itself choose who actually gets it. This is essentially a simplified version of the Sims “smart object” idea. The advantage here is that if you have less smart objects in a world than you do agents, you should get a significant cost saving on the calculations involved. The only agents allowed to request access to the smart object would be the ones that the object itself has detected within its proximity.

Another advantage of the smart object system is that the objects themselves can have more logic involved above the simple “am I available to be used” logic. It might be that some smart objects require a number of agents to be involved before the interaction is possible. This multi-agent synchronisation can get pretty complex, especially when there are potential failure states. Having a reactive system that can gracefully fail and release any agents tasked on the smart object is a requirement for this kind of system to work.

Solution 3 – Rely on variety

As the problem is simply that agent’s are all trying to acquire the same object, another obvious answer to this is to simply have different objects and try and make sure that agents choose from the available choices rather than all synchronizing on one specific object. The problem with relying on this notion is that eventually unless you artificially ensure that all objects within a world are maintained in equilibrium, you will inevitably achieve starvation of objects of a particular type. Imagine a case where you had a pack of lions who could only eat zebra’s. Eventually if the zebra population was not replaced, the lions would converge on whatever zebra’s were available in greater and greater numbers, eventually leading to complete extinction of the zebra population. So I guess your thinking “why is it that zebra’s don’t die out then?”. That’s a good question. One possible reason that the zebra population doesn’t collapse may be that the population regeneration rate is faster than the predators can kill them off. Another reason might be that lion’s are a bit lazy and will take on any food source available. In essence they have more than zebra on their minds for food sources, so they spread their attention across multiple types of prey.

Using this principle, all we would need to do is to ensure that our predator agents simply choose from a variety of prey and ensure that enough prey types were available so that behaviour would never converge to cause extinction. This suggests that some system is providing a method of ecological overview, adding population to prey types that are being killed to replenish the stocks.

Solution 4 – Enforce varying selection

The issue can also be tackled by taking on the root cause of the potential problem. That being the selection of prey being narrowed to one species. If we artificially enforced varying selection by the predator by simply not allowing it to eat any prey at a higher frequency than any other, we would achieve the equilibrium we require in the system. However there is a downside to this solution, in that the behaviour of the predator is unlikely to feel very natural. In nature predator animals DO have a propensity to prey on a specific subset of other creatures. This might be due to past successes, or geographical availability.

So what is the answer?

Right now, I am considering the smart object route. Because it is a very flexible system in terms of multi-agent tasks. Although we might think of predator/prey situations, a smart object system is just as likely to facilitate a social situation (for example kids on a see-saw) as it is to facilitate a predator/prey scenario.

0saves
If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.