Understanding Behavior Trees


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. However, they do not provide any modularity for states; you can’t reuse states to provide logic for different goals or situations without rewiring them. Behavior trees (BT) on the other hand take a different approach…

States or Behaviors

Behavior trees focus on increasing the modularity of states by encapsulating logic transparently, for example by using nested states. Certain hybrid HFSM implementations provide this feature also.

Figure: A tree made of modular behaviors.

The secret is to remove the transitions to external states, so the states become self-contained. In fact, once you do that, they’re not really “states” anymore because they don’t have transitions; they’re just behaviors, or a collection of actions that execute and terminate.

A Programming Analogy

You may ask, since the transitions are no longer encoded explicitly in each state, how is it possible to sequence behaviors using a behavior tree?

This is done using the same method as most programming languages — which is demonstrably more scalable. In C++Python or any other modern language, each operation does not contain a pointer to its successor, as it would be difficult to reuse these operations in different contexts (like calling them from another function).

Instead, operations are inserted into a parent scope (e.g. in a function, or for a conditional check), and they are executed according to the semantics of the parent scope. So in essence, the transitions between the operations are automatically defined based on which type of parent scope is chosen.

Why Behavior Trees Work

If you make your BT implementation extensible (so any type of scope, or composite behavior can be added), it becomes as powerful as any programming language. But at the same time, BTs remain very simple and usable when you provide standard composites such as sequences and selectors.

In fact, you can rebuild most state machine using only sequences and selectors. Then adding custom decorators into the mix you get something extremely powerful yet still very intuitive.

Ultimately, it is possible to translate a simple BT of sequences and selectors to a FSM if necessary. The FSM does you more control over the individual transitions, but the BT make the logic modular and easier to reuse.

3 Comments ↓

#1  Joerg Schlegel on 11.09.07 at 11:35 am

Hi Alex,

with great interest I read the articles about usage of behavior trees for modeling hierarchical behavior on your web site. But (as an AI beginner) I wasn’t able to find the answer to one question:

How could the dog - modeled using a BT - react to occurring events? Lets say it’s resting leaf node is activated and suddenly a cat enters his sight. If I understand the BT correctly there is no mechanism to deal with such events, or? But imho the reaction to events is very important in dynamic environments and gives an observer the impression of intelligence.

Using a FSM instead of the BT I’ll have a harder time to model the hierarchy of behavior, but reaction to events is easy, they could just be connected as transitions.

I would be really glad about a short answer.

Best Regards,
Joerg

#2  LM on 11.09.07 at 5:32 pm

Hi, Joerg.
I think parallel behaviors will do the trick. Just put “Watch for cat” and “Do smth” behaviors in parallel and implement override priority to “Watch for cat” tree branch, so if it triggers it will override all current actions in “Do smth” tree branch.

#3  Sander van Rossen on 07.01.08 at 9:36 am

“each operation does not contain a pointer to its successor”

That’s not entirely true … after all, modern programming languages have functionality like ‘goto’ and similar constructs that let you move to another point in the code …


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值