Using a Domain Specific Language for Behaviors

Alex J. Champandard on June 4, 2007

After having worked out the overall design for your actors, you’ll start creating specific behaviors for all the situations you have in mind. Now, if you use a standard programming/scripting language for this, you’ll end up with a very low-bandwidth approach to express what you have in mind. The actual behaviors will get lost in the syntax.

Instead you should use a domain specific language. In the case of game AI, a DSL is a way to express your behaviors as modular blocks that work together. There are two ways of doing this…

Finite State Machine

A FSM consists of a set of states, which you can connect to each other. When a state is active, connections may trigger a state transition if a condition is true.

See this article for more details:

Using this approach, you can design your behaviors to the smallest detail. Of course, ideally you’d need a tool to get the state machine into the game without having to re-implement the state machine as a script.

A hybrid hierarchical state tree.

Behavior Tree

The alternative to a flat state machine is a behavior tree. Behaviors are organized hierarchically, and call each other to achieve tasks.

Discussion 1 Comments

fattie on May 7th, 2009

The link to a set of articles about hierarchical logic on this site is broken. Probably, this has happened after transition.

If you'd like to add a comment or question on this page, simply log-in to the site. You can create an account from the sign-up page if necessary... It takes less than a minute!