A behavior tree is a hierarchical control pattern for selecting and executing behavior. Its nodes represent conditions, actions, and control-flow choices, producing success or failure rather than Boolean values. section 6.1 section 6.1.1
Build a tree from a small set of cooperating node types:
- Selector or fallback tries children in order and stops at the first successful child. section 6.1
- Sequence runs children in order and fails when any required child fails. section 6.1
- Condition checks state, while an action performs work; decorators wrap behavior and parallel nodes support dual execution. section 6.7
- Execution proceeds from top to bottom and left to right, falling back when a sequence cannot continue. section 6.1.1
Choosing what to eat
A root selector first tries a sequence containing Has apple and Eat apple. If the condition fails, it tries a second sequence containing Has pear and Eat pear. This makes the tree an explicit decision path rather than a tangled collection of state transitions. section 6.1.1
Running a tree with Python
Using py_trees, define custom condition and action classes, instantiate them, place each pair in a Sequence, and attach those sequences to a root Selector. Change condition results or remove a sequence to observe different behavior. section 6.1.3
Figure 6.8 The ABT for the coding challenge
The coding-challenge ABT shows how separate assistants can perform, review, and verify work through action and condition nodes. section 6.3.2
