Behavior trees
With decision trees focusing on the if…else
style of action selection and state machines focusing on the statefulness of actions, behavior trees fill a nice middle ground with reaction-based decision making.
The behavior tree node
Behavior trees are composed solely of different types of nodes. Based on the node type, the behavior tree will interpret child nodes as actions and evaluators. As we'll need to distinguish each node instance type from one another, we can create an enumeration of all supported node types: actions, conditions, selectors, and sequences.
Creating an instance of a behavior tree node merely sets the node type and the name of the node:
BehaviorTreeNode.lua
:
BehaviorTreeNode = {}; BehaviorTreeNode.Type = { ACTION = "ACTION", CONDITION = "CONDITION", SELECTOR = "SELECTOR", SEQUENCE = "SEQUENCE" }; function BehaviorTreeNode.new(name, type) local node = {}; -- The BehaviorTreeNode's data members. node.action_ = nil; node.children_...