Advertisement

FSMs vs Behaviour trees in gameplay programming?

Started by June 16, 2014 06:02 AM
4 comments, last by IADaveMark 10 years, 5 months ago

Hi all,

so I was just recently learning about Behavior trees and found them interesting so I decided to implement them. But what I don't understand is, are BTs a replacement for FSMs? in other words, can BTs do anything FSMs do?

I have asked the question here (no answers) with a concrete example that I would love to see how to represent it in a BT.

Your help is greatly appreciated, thanks!

My understanding is that BTs are a supserset of FSMs. Specifically, you could plug a FSM anywhere in a behavior tree (i.e. it's just a node in a behavior tree).

Advertisement

Thanks for your fast reply. Yes I also read that you could plug a FSM in a BT, but I'm wondering if a FSM can be represented as a BT - More specifically, I'm wondering if the tiger statue puzzle i mentioned in my original question can be somehow a BT instead of an FSM, does it make sense? or a FSM is more suited for these types of things? (in my game I have much more similar triggers to that one I mentioned, they change state - you interact with them once, they do A, interact with them in a different way they do B, etc. so I'm wondering if using a BT is better here than an FSM...) Thank you.

BTs are not really a superset of FSM, because a tree does not contain any cycles. I'm sure, that you can implement the same or atleast similar logic in both representations, but it will most likely get more complex in one of the two representations.

BTs are very flexible and easy to expand, therefor you can integrate other AI logic as special nodes, therefor adding FSMs should not be a problem. Both, BT and FSM, have kind of memory (path in BTs and state in FSM), but the follup interaction is strongly defined in FSM (state transitions) whereas a BT have the option of interrupting running actions and initiating new actions (priority nodes).

My rule of thumb is to use BTs where you have more script like behavior, eg the approximation of the AI of a human being and to use FSM where you have more rule/state based behavior.

A BT can do anything a FSM can do, but you kind of have to cheat. You can set states in the world that can be queried by the BT.

The way I think of a BT, it's simply a boolean expression in a language like C, where you use operators && and || (with short-circuit evaluation) to combine calls to functions with no arguments that return bool. In that interpretation of BTs, you can write something like this:

(state_s1_is_set() && show_text() && set_state_s2())
||
(state_s2_is_set() && ...

Please note... don't confuse an architecture with a reasoner. Theoretically, no matter what you use to make a decision, an agent ends up in a state. BTs simply lift the transition logic out of the states themselves and put them into a highly organized reasoner that operates independent of the state.

Dave Mark - President and Lead Designer of Intrinsic Algorithm LLC
Professional consultant on game AI, mathematical modeling, simulation modeling
Co-founder and 10 year advisor of the GDC AI Summit
Author of the book, Behavioral Mathematics for Game AI
Blogs I write:
IA News - What's happening at IA | IA on AI - AI news and notes | Post-Play'em - Observations on AI of games I play

"Reducing the world to mathematical equations!"

This topic is closed to new replies.

Advertisement