Mindflock.com
Social Game Artificial Intelligence
Social Game Artificial Intelligence
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.
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.
October 24, 2009 - 2:52 pm
Solution 1 is actually a lot like Solution 2, just without being optimised imo.
Each object that has an “interest” in a target object should know roughly how long it will take to reach said target object. In its simplest sense, the distance of its path to the target object. Each object will store this data naturally as part of its path finding.
Given this you can create a list of objects and their approximate arrival times… it will be nice and quick to sort into an ordered list of arrival times.
If your arrival time isn’t fast enough you get refused being allowed that target object… by this point you would have likely decided to rewrite the logic to be very similar to Solution 2
October 24, 2009 - 6:25 pm
Its not quite that simple though. Given this is done per-update and per-agent. You would have to calculate the intercept time of each agent. But of course blocking one agent with another would significantly muddy the waters in that case. Given the target itself is moving, it means that the intercept time also changes on the fly (given different relative velocities).
October 24, 2009 - 8:57 pm
« you will inevitably achieve starvation of objects of a particular type. »
Actually no, you won’t. If there is less preys, the predators will die, so the preys can reproduce again. This is what explains lemmings “suicide”, and is modeled by the Lotka-Volterra equation for example. In this model (the simplest prey-predator model I know of), zebras don’t die because lions die before.
October 25, 2009 - 11:53 am
@zoombapup
Correct, but that is why I talked about approximate times, not absolute times.
Just query the other agents for their last calculated arrival time, don’t make each agent calculate every other agent’s arrival time every update… that would be daft
You are looking to avoid a situation were something *looks* bad (ie, trains) so approximate values should be fine – you’d be able to get them accurate enough to it *look* correct etc without needing heavy calculation.
October 25, 2009 - 6:48 pm
Craig: yeah, but the target is moving and can move in varying directions (for instance a zebra changing direction to run from lions), so the chasing lion needs access to both its own trajectory, the zebra’s and any other lions. Youre right, in that each lion could query the other lions directly for thier time of intercept. Which is effectively what the smart object would do. The upside of doing it in the smart object is that the smart object could detect all lions that could potentially intercept it. There are less smart objects than there are lions so it should be more efficient. Downside is that you would lose some of the lions from the chase fairly quickly.
Now of course the lions may be using group tactics to bring down the zebra, but that is a tad outside of the scope of discussion.
October 25, 2009 - 6:51 pm
Cygal: That assumes that the predator will die due to being deprived of prey within its reach. If you actually compress the potential space, there’s no way the predator population will collapse fast enough to stop the annihiliation of the prey population. Only when the prey can move away from the predator (and subsequent cost of predator capturing prey increases) can you reproduce the population. Think of it this way, a bunch of zebra locked in a football field vs some lions. Who do you think dies off first?