Artificial Intelligence: Guards
November 25, 2016
Last week I wrote about getting AI bystanders acting in the world of Robyn HUD. Bystanders have a limited variety in the basic types of actions they need to do. Building upon that system, I’ve since moved onto the guards that populate the same world. The guards that get in the way of the player and his partner, Robyn.
The guard AI for Robyn HUD starts with the foundation laid down for the bystanders. If guards are unaware of Robyn’s presence then they can wander about doing various simple actions like talking to other people or getting lunch or the like. However, moving beyond those basics, guards have a few more capabilities and consequently more sophistication than their bystander counterparts.
As with bystanders, guards have rigidly defined rules that determine the general “action state” they’re in. This is built on top of the awareness levels that the bystanders use. To recap, there are four levels of awareness that AI agents can have in Robyn HUD:
- Unaware – The agent isn’t aware of any suspicious disturbances in the environment.
- Suspicious – The agent has seen or heard something suspicious that heightens their attention but doesn’t cause them to go looking for the source of those suspicions.
- Alert – The agent knows something is definitely wrong somewhere but doesn’t currently know where that “somewhere” is.
- Crisis – The agent knows that Robyn is the source of the disturbances and can either see her directly or knows/believes she’s in the immediate vicinity to be dealt with.
Bystanders, when they’re in the unaware and suspicious states, will wander around doing bystander-y things (talking to one another, admiring paintings, etc.). Guards too can do these things, but many of the guards in Robyn HUD will either prefer to remain at a designated post that they have to keep a watch on or else will go out on a patrol route. They’re not expecting trouble at this point, but they will be moving about and keeping an eye on things and causing obstacles for Robyn and the player to work around. As a technical point of note, most guards will start with an awareness of suspicious so that if anything “bad” does happen, they’ll immediately go to alert level and possibly even to crisis level.
Once a guard has reached an alert level of awareness, as soon as that guard sees Robyn, he’ll switch into the crisis level. At this point the guard’s behavior becomes more interesting as he actively responds to Robyn rather than passively waiting for her to do something wrong.
As mentioned earlier, the guards are largely rule driven in their responses. When a guard enters crisis awareness it’s because he can currently see Robyn directly. At this point, the guard begins chasing Robyn. Depending on if other nearby guards are also chasing Robyn, this particular guard may decide to radio or shout for help.
Once chasing begins, the guard will remain in the chase state until certain conditions are met that will pop the guard into another state. The possible states the guard can enter include:
- Arrest – The particular guard is the first one to catch up to Robyn. In this case, Robyn is caught. The guard then leads her to the exit of the level. If he reaches the exit with Robyn then she is arrested and the level ends with her being taken off to jail (in the following level the player will have to break her out of jail before resuming the rest of the story). The level in which Robyn is caught may or may not be considered a failure, depending on if Robyn was caught before or after fulfilling the goals in the level.
- Escort – If the particular guard reaches Robyn but finds that she has already been caught by someone else, then the guard will take up an escort position. He joins with the arresting guard to lead Robyn out of the level. My tests so far have only involved a handful of guards, so having them all escort Robyn is not a problem. I suspect once I get more guards into a level that it will start to look a little ridiculous if they’re all escorting (imagine 20 guards all following Robyn to the arrest point!). If this proves to be the case then I’ll probably enhance the AI so that if there are already a number of escorts then the particular guard will go off to resume patrolling or do some other trivial action.
- Search – If the guard is chasing Robyn but loses sight of her for a length of time, he won’t know where she is to keep chasing her. At this point he’ll begin searching his immediate surroundings to see if he can find her again. If he can’t then he falls back to alert awareness wherein he’ll go on patrol or do some other trivial action until he spots Robyn again so he can start chasing her.
- Confused – When a guard is in any of the chase, arrest, escort, or search states he is open to the possibility of becoming confused. This happens when either the player or Robyn acting autonomously do something to distract the guard. Maybe the player triggers a fire alarm or gives conflicting orders over the guards’ “secure” radio frequency. Or maybe Robyn does some clever evasion move that surprises the guard. Whatever the distraction, the guard enters the confused state, during which he essentially become motionless for a short time, giving Robyn a chance to escape. If she does, then the guard will go back to the alert awareness level. However, if Robyn’s still visible when the guard stops being confused then he’ll reenter the chase state to pursue her again. It’s important to note that the more distractions a particular guard is subjected to, the less they will affect him. Play testing will be needed to determine how quick the drop off is and whether or not a guard should be able to ignore distractions entirely.
Guards have one goal in their virtual lives: to capture Robyn if they can. As such, the various states they can move through are all highly structured and deterministic. There’s not a lot of random chance involved in what a guard will do in any given circumstance. The same cannot be said for Robyn herself as shall be explained in a future production update.