Hierarchical Logic in Game AI
↓ 12 articles ↓
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
September 6th, 2007 | Alex J. Champandard
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. […]
September 5th, 2007 | Alex J. Champandard
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 […]
August 2nd, 2007 | Alex J. Champandard
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 […]
July 26th, 2007 | Alex J. Champandard
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 […]
July 10th, 2007 | Alex J. Champandard
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 […]
July 3rd, 2007 | Alex J. Champandard
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 […]
July 2nd, 2007 | Alex J. Champandard
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 […]
June 16th, 2007 | Alex J. Champandard
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.
June 10th, 2007 | Alex J. Champandard
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.
June 8th, 2007 | Alex J. Champandard
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.
June 6th, 2007 | Alex J. Champandard
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).
June 4th, 2007 | Alex J. Champandard
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.