Some time ago someone asked me how AI is implemented in Atom Zombie Smasher. So, here’s a short writeup on it.
In my first attempt at zombie AI, they began as mindless automatons. Here’s how they first worked:
Find a random place to walk to.
That’s what zombies do, right? They like to take walks. It looks disgustingly simple, but was surprisingly effective. The zombies spread across the map in a fairly natural-looking way.
A problem arose when the human population dwindled down to very small amounts. When just a few civilians were left, the game became awkward. These last holdouts had an extremely good chance of surviving for a very long time, due to how zombie wandering was left completely up to random chance.
As a result, the finale of a map tended to drag in an anticlimactic way.
For my next attempt, I tweaked the zombie AI:
Select a random civilian.
Walk to that civilian’s position.
Zombies were transformed into extremely efficient civilian-hunting machines. This fixed the problem of map finales dragging on - when just a few humans were left, they were promptly devoured.
A new problem arose: the game was now nigh-impossible. Once a chain-reaction infection starts, it’s difficult to stop. Due to how these new hunter-zombie powerhouses behaved, these chain reactions were now happening from the moment you started the map to the time you stopped. Furthermore, the cold efficiency in which they behaved was more akin to a special weapons team rather than rumpled zombies.
For my third (and final) version of the zombie AI, I combined the above two systems together:
Zombie makes a random decision:
25% chance the zombie hunts a random civilian.
75% chance the zombie wanders the map randomly.
This achieved the “rrgghh, brains!!” mindless behavior expected of zombies, but also ensured civilians were getting eaten at a reliable rate.
But really: implementing zombie behavior is a bit of a cheat. One of the nice things about zombies is that if they behave stupidly, it’s generally accepted - after all, they’re zombies. A zombie is expected to act like a drunk fella, aimlessly stumbling around and making questionable decisions.
The hard part was implementing believable civilian AI.
Civilians are the currency in the AZS world: the more civilians you save, the better. As a result of that, it was important that civilians were fairly capable of self-preservation. Here’s what runs through a civilian’s brain:
If I’m near a zombie, run away from it.
If I’m in range of a rescue helicopter, run toward it.
Civilians get a “panic” speed boost when running away from zombies, allowing them to outrun pursuers. During this panic state, civilians wear blinders - they run toward their destination with complete disregard for their safety. As a result, a panicked human during the beginning of a zombie outbreak has a good chance of surviving; panicking during the peak of an outbreak, not so much.
An unintended effect of this speed boost was that the little civilian dots were given a wonderful little personality. On screen, you see a civilian dot wander near a zombie and high-tail it the other way at a sprinting pace. The abstracted visuals make it easy to fill in the blanks - you can imagine the civilian’s surprise at seeing the zombie, the crazy flailing-arms as they run away screaming, having no idea what street they’ve ended up on.
I find AI to be one of most difficult parts of game development. It’s very demanding on both a technical and design level. AI is not my strong point, so AZS mostly designs around that - zombies are not expected to be intelligent, and civilians are prone to panic & hysteria during the end of the world.
Games with good AI are rare finds. But when a game nails the AI, it makes a world of difference. The Halo games are good examples of this.
I’ll end this with a bot for Quake II that I thought was particularly clever, the Eraser Bot. Basically, the Eraser Bot learns from players. As you run around the map, you drop an invisible “popcorn trail” wherever you go. The bot then uses this data for its pathfinding. As you play more, you generate more path data, making the bots “smarter.” They begin to hunt you down with ruthless efficiency, taking unexpected shortcuts and sticking crazy trick jumps.
Maybe I’m just terrible at shooters, but I found the bot’s effectiveness to be pretty frightening!