Extraction: AI and behaviour

Extraction - AI ThumbnailThis is the third part of my game design series. In part one I gave an overview of the game and in part two I described the map generation algorithm. This post describes the AI used in the game and how a combination of simple rules play off each other and combine to create useful and engaging simulation.

Extraction consists of three parties – the zombies, the survivors and the player, and here we’ll focus on the rules governing the behaviour of the zombies and the survivors.

Mechanically a single actor (zombie or survivor) has a location and a state, and makes an action based on that data. The only actions available are to move in one of the cardinal directions (north, south, east or west) or remain where they are. More than one actor can occupy a location, so the only restrictions on movement are terrain-based – if the location north of a player is open they can move north, and so on. Actors have a “awareness range” representing the distance at which they can see or hear events, items and other actors, and nothing outside of this range can govern their actions. Zombies have a larger awareness range than survivors and it is omni-directional, whereas survivors have a more limited awareness range and in some circumstances are only aware of things in the direction in which they are facing.

Zombies

Zombies, being mindless hunters, have a relatively simple set of decisions governing their movement.

  1. Extraction Vehicle (player)
    • Can they see it?
    • Can they move closer to it?
    • If so, move towards the extraction vehicle.
  2. Targeted Survivor
    • Is the zombie currently chasing a survivor?
    • Can they move closer to them?
    • If so, move towards the current target.
  3. Target a Survivor
    • Can they see any survivors?
    • identify the nearest one they are able to move closer to.
    • If one is identified, set it as the current target and move towards it.
  4. Beacons
    • Can they see any beacons?
    • Identify the nearest one they are able to move closer to.
    • If one is identified, move towards it without setting it as the current target.
  5. Wander
    • Move in a randomly selected direction.

Survivors

Survivors are a little more complex and have more factors governing their actions.

  1. Extraction Vehicle (player)
    • Can they see it?
    • Can they move closer to it?
    • If so, move towards the extraction vehicle.
  2. Beacons
    • Can they see a beacon?
    • Is it pointing to anything?
    • If so, move towards the beacon’s “parent” (either the next beacon in the chain or the extraction vehicle.
    • Set the beacon’s parent as the current target. They know where safety is.
  3. Zombies
    • Can they see a zombie? This is direction-dependent, a survivor can only spot zombies in front of them.
    • If so, remove their current heading from the list of available directions – a survivor will not flee towards the zombie that scared them.
    • Increase their “fear” counter to somewhere between their current level and the maximum possible value.
    • If there is a direction to flee in, choose one at random.
    • Otherwise do not move – freeze in terror.
  4. Head for Safety
    • Do they have a current target?
    • If so, they have a small chance to lose interest in it.
    • If they have a target and do not lose interest, continue moving towards it, even though it may no longer exist.
  5. Wander
    • There is a roughly even chance of continuing in their current direction.
    • If that direction isn’t valid, or they change their mind, move in a random direction.

Emergent Behaviour

That’s it. Two sets of rules, one for each actor type. Together they work rather well. Given even a small number of zombies and barring any inconvenient geography, without any interaction from the player the survivors will eventually all become zombies.

A few interesting and unplanned behaviours fell out of these simple rule sets. Firstly, the fact that both zombies and survivors prioritize the extraction point means that a game can suddenly descend into tense chaos as the player has to weigh up how long to stay in place, pulling out survivors while the zombies cluster around killing the grouped survivors and damaging the extraction vehicle. Do you pull out and relocate before you take too much damage, abandoning a bunch of survivors to the gathered horde, or try to hold out just a few more seconds? Even if you do pull out, survivors will still be following the chain of beacons you placed, heading right for the horde…

Another side effect was that a scared survivor, running from a single zombie, could very easily run headlong into a group of wandering zombies, turning them from a harmless out-of-the-way group into a very active threat, potentially pulling them out of their niche and into the game.

Taking it Further

I’ve got a few ideas for where to go from here, but the trick is to do so without upsetting the current balance. I’d really like to have a system where a zombie makes a noise when spotting a survivor, in turn attracting nearby zombies to the chase. In a reversal of that, it would also be interesting to explore the idea of survivors communicating to one another – screaming when they see a zombie to alert others to the threat, and pointing out the way to safety when they see a beacon or the extraction vehicle.

The risk in adding to the rules is in making it too complex, which has the counter-intuitive effect of making the game more predictable and less dynamic or emergent. The closer you get to having a specific action for a given situation, the less scope for unexpected behaviour.

This section is the part of the game that interested me most – getting my head around the design of a game was fun, but AI has always fascinated me. Emergent behaviour is a well-established concept, but it’s always fun to have a play with it and see where it takes you. When all’s said and done, the very core of Extraction boils down to to implementations of a move function, and that should tell you all you need to know about how interesting and deep AI and emergent behaviour can be.


Leave a Reply

Post Navigation