Artificial Intelligence: Robyn

May 26, 2017

It’s been some time since I wrote about the artificial intelligence for guards and for bystanders in the upcoming Robyn HUD game. At last I’m back to write on the subject of the artificial intelligence for Robyn herself. Robyn’s AI requires a level of sophistication far greater than the other agents populating the game world.

At a high level, the major difference between Robyn and the other agents in the game is that Robyn’s AI needs to be proactive while the other agents are reactive. The other agents, be they bystanders or guards, perform simple behaviours that essentially consist of walking to a spot and optionally running a brief animation or saying a line of dialog. The list of simple behaviours they can choose from changes depending on how aware they are of Robyn. A bystander who is aware of Robyn as a thief will run away from her or call the guards if they spot her. A guard in the same circumstance will chase after Robyn to try to catch her. In either case, the given agent is reacting to the presence of Robyn. This makes it easy to govern that agent’s behaviour with a limited set of well-defined rules.

When we turn our attention to Robyn; however, she doesn’t just have to react to a given situation, she has to be able to prioritize and make decisions on her own, working towards the goals of a given mission. For example, Robyn may be placed in a location where she has to find a key that unlocks a door that gives her access to a security room where she can connect the player into computers to help her carry on with her ultimate goal of stealing some important piece of information. All the while she has to be alert to guards and be able to decide to hide or run away as the situation calls for. On top of all this, she has to take into consideration the prompting of the player, who is serving as her eye in the sky to try to keep her safe from security and to hack computer based obstacles that Robyn herself can’t deal with.

Goals

A goal constitutes a type of task that Robyn can perform in the game. Whether it’s stealing an object of some worth or evading pursuit, all of the different actions Robyn can perform are classified into different types of goals. At the time of writing, I’ve currently implemented the following goal classes for Robyn:

  • Explore – Robyn doesn’t have psychic powers. She doesn’t know where mission critical items are within a given environment. She therefore has an explore goal that causes her to move through her surroundings to see where different objects are. In programming terms, Robyn does know where items are in 3D space but doesn’t know what those items are until she gets close enough to see them. So she may know the positions of five different objects in her immediate surroundings, but until she sees them she doesn’t know which one is the key that will unlock the door. It’s easier from a programming standpoint to navigate to a specific position, such as the position for an object, than to do a general wandering through the environment.
  • Flee – Robyn’s a thief and she wants to do her best not to get caught by guards. In the event that her presence becomes known, she needs a goal to try to get her out of trouble and that’s what the flee goal is. The flee goal itself is divided into several different potential sub goals:
    • Hide in Vents – In some environments the svelte Robyn can use air vents to worm her way through from one location to another. The guards she encounters aren’t blessed with her slim frame so are unable to follow her through vents. Hiding in a vent is a good way for Robyn to get to safety.
    • Hide in Room – Sometimes there just isn’t a vent handy to hide in. In such cases, Robyn may be able to throw off pursuit by finding a hiding spot within the room she’s in. Such spots might be behind pieces of furniture or within handy closets. They can take her out of the immediate sight of pursuing guards but may not fully protect her if the guards begin performing a methodical search.
    • Evade – If Robyn is being chased she may simply not have the opportunity to hide. However, she can still use the environment to her advantage. Rolling over counters, sliding under tables, or doing a short wall run or other clever move can put some distance between her and her pursuers. As an added bonus, such moves temporarily confuse guards, halting them in their tracks and giving Robyn a little more time to escape.
    • Leave – If Robyn doesn’t have any good hiding or evasion options or she’s close to a door, her best bet for escaping might simply be to move on to an adjoining room to the one she’s currently in.
  • Instruction – During a heist, the player may issue ad hoc instructions to Robyn. This covers a wide range of options from the player’s perspective such as retrieving a key or a document, “handshaking” a computer system so the player has access to it, or moving to a specific location in the environment. From Robyn’s perspective these tasks boil down to walking to a specific location and performing an animation or saying some dialog much like the bystanders and guards.
  • Take – Like a good thief (or adventure game character) Robyn tries to take everything that’s not bolted down. This could be taking keys or tools that will help her progress in the current mission or else stealing valuable items that can be fenced for money to purchase useful tools for future missions.
  • Plan – Most missions are prefaced with a high level planning session. Using the planning interface the player can lay out a basic plan of attack. Within the mission, the plan goal for Robyn is similar to the instruction goal, just with Robyn proceeding through the steps of the plan rather than receiving ad hoc instructions on the fly.
  • Wait – Sometimes a good thief needs patience. The player can issue special wait instructions to Robyn, which cause her to hang out where she is for a brief time or until the player issues a continue instruction.
  • Wander – Robyn’s only one half of the team and she may find herself in a situation where she can’t proceed until the player overcomes some hacking challenge. Rather than just being rooted to the spot staring at her toes, Robyn may choose the wander goal to go off and visit some random part of the environment.

As Robyn and the player progress through a mission Robyn is constantly evaluating each of the above goals. In any given moment, Robyn will choose the goal that is most attractive to her. From a programming point of view, each goal is evaluated and given a different rating from 0 to 100. Whichever goal has the highest rating is the goal Robyn will pursue.

Fuzzy Logic

Calculating the weight for a goal depends on a variety of factors specific to that goal. For example, Robyn’s explore goal takes into account how many of the items Robyn has seen in her environment. The more items she’s seen the better she knows the environment and so the lower the weight to continue exploring. The explore goal also factors in how far away an object to explore towards is. The farther a given object is away from Robyn the less attractive it is for her to move towards it.

These different factors are fed into a fuzzy logic artificial intelligence system. At a high level, for each factor that contributes to the weight of a given goal, there exists a fuzzy function that takes an input value and returns an output value indicating the relative attractiveness of a given factor. These output values can be thought of as plateaus where multiple input values may map close to the same output value before taking a step down to a lower plateau.

For ease of use, the fuzzy functions I’ve created return percentage values. In the case of the explore goal, one input value is the distance needed to walk from where Robyn currently is to the object to explore towards. The fuzzy functions here have been setup in such a way that objects that are very close at hand have a high weight. That weight drops faster and faster the farther away an object is. Similarly the weight for exploring in general drops faster and faster as Robyn sees more of the total objects within the level.

The full details of a fuzzy logic system are beyond the scope of this simple blog. Suffice to say that the fuzzy functions are easy to rapidly adjust to find output weights that ensure no one goal becomes disproportionate to the others.

Trust

One of the interesting features of several of Robyn’s goals is the concept of trust. Plan goals, instruction goals, and wait goals are all issued to Robyn by the player. The player forms the plan. The player sends ad hoc instructions during a mission. The player tells Robyn to wait for a go command, ostensibly to keep her safe.

Throughout the game, players will have the opportunity to affect how much Robyn trusts them. This can come from the player talking to Robyn and other characters within and between missions. Some conversation options may increase Robyn’s trust in the player, some may decrease them. Trust can also be impacted based on the instructions the player gives Robyn during a mission. For example, if the player tells Robyn to wait where she is and she gets caught, her trust in the player may decrease. Conversely, if Robyn is caught by the guards and is being escorted out of a location to be hauled off to jail but the player uses their hacking abilities to create a diversion that allows Robyn to escape then Robyn’s trust in the player may rise.

As Robyn’s trust decreases the less likely she will be to follow the player’s instructions. For example, if Robyn doesn’t trust the player and the player issues an ad hoc instruction, Robyn will still consider the instruction goal but will give it less weight than she would if she fully trusted the player. This may result in other potential goals having a higher weight. Robyn may then decide that lining her own pockets by stealing some object of value readily at hand is more important to her than following the player’s instructions.

Not to worry though, no matter how low Robyn’s trust in the player drops it will never reach the point where a mission can’t be completed. It just may mean the player has to do a few things in mission to either rebuild Robyn’s trust or to coerce her into the desired action.

Conclusion

At this point in development Robyn’s AI is working well. There’s still some tweaking of the goal factors and goal weights that needs to be done, but for the most part Robyn gives the impression of working autonomously through an environment in an intelligent fashion. I need to get a few more levels built that will put Robyn into different situations to truly test the AI system but so far things are looking well.