A.I. Systems

My first try at an A.I. system was when I was making Death Zone Zero. I was inspired by the A.I. system in Dragon Age: Origins.

If you’re a programmer, one look at these screenshots should explain how the whole thing is set up.

To be clear about it, it works like one long if-then-else-if chain, but the important distinction is that you can add, remove, and change those if’s during runtime.

So its basically a list of conditions, with an action to do for each, when the corresponding condition is met.

You can also describe it as a priority list. It checks from the top first. If it found something to do at the top, the program won’t bother looking at the bottom conditions. Of course the program continually evaluates this long if-then-else-if chain (always starting from the top), so there is a chance the bottom entries can be triggered. It depends exactly on how lenient the conditions are.

Here is an example:

  1. Am I dying? Then I should escape from the enemy.
  2. (Assuming I’m not dying,) Is an enemy in attack range? Then I should retaliate.
  3. (Assuming I’m not dying and not being attacked,) Did I detect an enemy? Then I should pursue him.
  4. (Assuming I’m not dying, not attacked, & not seen an enemy) Then I have nothing to do, I’ll just wander/patrol the area.

That is basically the most common A.I. you’ll ever find in videogames. I’ll reword everything to make that clear:

  1. Am I losing? Then assume a defensive position.
  2. (Assuming I’m not losing,) Is an immediate threat found? Then do something about it.
  3. (Assuming I’m not losing and no immediate threats,) Am I seeing a potential threat on the horizon? Then take it into account.
  4. (Assuming I’m not losing, and no immediate or potential threats) Then improve myself and keep on guard.

You’ll notice each condition expects that the ones before it failed. This is essential in making it a priority list.

You’ll also notice the entries are ordered from most important to least. This is also needed to make sure the A.I. works as intended.

Building upon this, I had added the ability to add more than one condition for an action. The conditions would then be attached together in essentially AND operators. If one condition fails, the program won’t bother with the other conditions and move on to the next entry in the list.


What I had problems with back then, was how to make enemy A.I. do coordinated attacks (flanking, one distracts while the other attacks from the target’s blind spot), and to make an A.I. switch between different priority lists.

Swapping Priority Lists

Say the enemy can act stealthily if he wanted to. His abilities for stealth essentially mirror what he does while not in stealth: escape, attack, pursue, and patrol, but again, all as a stealthy variation. What I had been thinking then, is to add an action to make an A.I. switch to a different priority list if the situation calls for it.

Moving On

Then a lot of things happened and Death Zone Zero is currently on hold. Now that I am tackling A.I. systems again, I’m taking a pause and wondering how to do things again. I’ve heard about behaviour trees and how it’s very well suited for videogame A.I.

I ended up reading this #AltDevBlogADay article on behaviour trees, and chanced upon one of his references: the A.I. system in the PSN game, Swords and Soldiers (part 1, and part 2).

The more I read it, the more I realized, “This isn’t a behaviour tree, this is more like the priority list system I made up long ago”.

The A.I. system in Swords and Soldiers is very similar to the priority list system I made up long ago.

The nice thing about behaviour trees is you can create one that works exactly like a priority list.

The truth though, is that they can have a more sophisticated structure that potentially make them work a lot more “intelligently”. If the priority list is like an if-then-else chain, then the behaviour tree can add more, like a switch statement, nested if’s, and even loops. Behaviour trees are like a visual programming language but made for a more specific purpose (i.e. videogame artificial intelligence). Part of their charm is to make the design of A.I. a lot more accessible to non-programmers, the same way my priority list does.

The only problem is its a lot harder to understand. For that, I recommend the article I mentioned above.

There’s also this hour-long video about behaviour trees in aiGameDev.com. An account is required, but subscription is free. You could, however, watch that same video for free, without registration, in this three-part series: part 1, part 2, and part 3.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s