Hierarchical Logic in Game AI

12 articles ↓

Hierarchical Logic

Almost all AI engines these days are designed as hierarchies, whether it’s with finite state machines or nested scripts. Even mainstream programming languages are based on a hierarchy. But how does this help you make smart behaviors for your in-game actors? What are the major pitfalls to watch out for when designing them?

This series covers everything you need to know about hierarchical logic in AI. Here are the best places to start:

If you have any general questions about hierarchical logic, be sure to ask them! Comments on the individual pages are also welcome.

Recent Posts

Understanding Behavior Trees

One of the primary goals of game AI is finding a simple and scalable solution for editing logic. Finite state machines have the advantage of being quite simple, but for large systems you’ll need a hierarchical FSM to provide reusable transitions between states.
Such HFSMs are certainly a popular way for making scalable logic. […]

The Gist of Hierarchical FSM

This previous article discussed how traditional finite state machines don’t scale very well. FSM don’t provide ways for reusing logic in different contexts, which leaves you with a choice of two evils: redundancy or complicatedness.
Game developers have found many different solutions to this problem, but one is most popular these days.

Figure: A simple […]

Understanding AI Logic from the Bottom-Up

At the base of any game AI system, you’ll find actions and conditions. They’re not only the interface to the virtual world, but also the foundations of the whole logic.
Looking at an AI system from this perspective makes things a lot simpler when designing the system, because it helps you focus on the […]

Using Decorators to Improve Behaviors

How do you build complex behaviors without them becoming too complicated? Most modern games require intelligent and realistic actors to support the design, but it’s often difficult to create their AI.
One solution to this problem is to use modularity to assemble behaviors from simpler parts. Previously, you learned about sequences, selectors and […]

Enabling Concurrency in Your Behavior Hierarchy

Assume you have a tree of behaviors, with conditions and actions as leaf nodes, and sequences and selectors as branches. This type of logic is very linear, and will only ever do one thing at a time. So how do you get your AI to support concurrent behaviors?
The answer is to use […]

The Flexibility of Selectors for Hierarchical Logic

Most useful programming languages implement conditionals; they look like if or switch statements — and sometimes lookup tables. In the context of AI behaviors, a selector does the same thing by picking one of its child behaviors to run.

A selector based on probabilities, with three child behaviors.

In the previous article, you learnt how […]

The Power of Sequences for Hierarchical Behaviors

Sequences of behaviors may be nothing new, but they are very powerful. For decades, programmers have been assembling statements together as instructions that run one after the other. For game AI, it makes even more sense:

It’s such a simple idea that everyone understands it very quickly: from designers to testers, including producers!
Sequences […]

Termination Status for Behaviors

A termination status is a known code that each behavior returns once it has completed. Termination status codes are typically exposed in the common interfaces, as they are used everywhere.

Advice for Creating Hierarchical Logic

There are many ways to build AI with hierarchical logic, but increasingly game developers seem to be using the similar techniques. Here are a few tips to get you on the right track.

How to Build Hierarchical Behaviors

The main goal when implementing hierarchical behaviors for an AI engine is to allow them to be as modular as possible, while still allow them to interact with other behaviors. You have two choices: a centralized approach, or a decentralized one.

What Is Hierarchical Logic?

An AI has hierarchical logic if the behaviors are organized in a tree structure, where elements towards the top of the tree (i.e. parents) are responsible for and/or dependent on the behaviors towards the bottom of the tree (i.e. children).

Why Your AI Needs Hierarchical Behaviors

Modular behaviors provide the basic building blocks of any AI engine. However, it’s usually necessary to combine lower-level behaviors into more complex ones. Using a hierarchy is the most obvious next step.

Game AI Character