参考网址:

(128条消息) 行为树(Behavior trees)_念去去~的博客-CSDN博客_行为树

(128条消息) 状态机和行为树_PresleyGo的博客-CSDN博客_行为树和状态机区别

(128条消息) 行为树概念_白霞的博客-CSDN博客_行为树

devildevilson/tiny_behaviour: Behaviour tree header only library (github.com)

BehaviorTree/BehaviorTree.CPP: Behavior Trees Library in C++. Batteries included. (github.com)

BehaviorTree/Groot: Graphical Editor to create BehaviorTrees. Compliant with BehaviorTree.CPP (github.com)

基础定义

Tree nodes description

BehaviorTreeBuilder class methods:

Compositor nodes:

1
2
3
4
5
6
7
`sequence()` - updates all nodes until faces `Status::Failure` or `Status::Running`
`selector()` - updates all nodes until faces `Status::Success` or `Status::Running`
`parallel(minSuccess, minFail)` - updates all nodes, return `Status::Success` if `totalSuccess` >= `minSuccess` or `Status::Failure` if `totalFails` >= `minFail` else `Status::Running`
`memSelector()` - updates all nodes until faces `Status::Success` or `Status::Running`, next updation will start from that node
`memSequence()` - updates all nodes until faces `Status::Failure` or `Status::Running`, next updation will start from that node
`random(seed)` - updates random (depends on seed) node
`whiledo(predicate)` - updates all nodes while `condition == true`, returns `Status::Running` in this case, if `condition == false` does nothing and returns `Status::Failure

Binary nodes:

(Status::Success is true, Status::Failure is false)
conjunction() - Status first && Status second
disjunction() - Status first || Status second
equality() - Status first == Status second
implication() - Status first -> Status second (!(Status first) || Status second) (Status::Running = Status::Failure)
ifelse(predicate) - if contidion == true updates first, else second

Decorator nodes:

1
2
3
4
5
6
7
8
inverter()` - inverts `Status::Success` and `Status::Failure`, `Status::Running` ignored
`repeater(limit)` - returns `Status::Running` `limit` times, then return node status and resets
`limiter(limit)` - returns decorator's child status `limit` times, then return `Status::Failure`
`untilFail()` - returns only `Status::Running` or `Status::Failure`
`untilSuccess()` - returns only `Status::Running` or `Status::Success`
`failer()` - returns only `Status::Failure`
`succeeder()` - returns only `Status::Success`
`condition(predicate)` - updates child if `predicate == true` else returns `Status::Failure

Special nodes:

action(action) - userdefined action function, must return statuses

Other methods:

end() - use it after every Compositor or Binary nodes
add(node) - adds nodes to the current tree, NOTE: adding trees is under construction
leaf(arguments) - create userdefined action node build() - does some postworks and returns BehaviorTree pointer
debug(string) - just prints the string
setDebugCallback(callback) - set callback function for the error strings

子树命名规则

name default
input tree_[tree_name]in[action_name]_[value_name] {tree_[tree_name]in[action_name]_[value_name]}
output tree_[tree_name]out[action_name]_[value_name] tree_[tree_name]out[action_name]_[value_name]

节点变量

name default
input action_[action_name]in[action_name]_[value_name] {action_[up_tree_name]in[action_name]_[value_name]}
output action_[action_name]out[action_name]_[value_name] {action_[up_tree_name]out[action_name]_[value_name]}

条件变量

name default
input condition_[action_name]in[condition_name]_[value_name] {action_[up_tree_name]in[condition_name]_[value_name]}
output condition_[action_name]out[condition_name]_[value_name] {action_[up_tree_name]out[condition_name]_[value_name]}

子树/节点/条件的命名规则

name name optional name optional
子树 Subtree_[tree name]
节点 Action_[action name]_Output Action_[action name]_Input ActionBase_[action name]
条件 Condition_[condition name]

相关注意事项

  • 同级子树,多个set对应一个get,以get所在变量名定义default.
  • 同级子树,多个get对应一个set,以set所在变量名定义default.
  • 同级子树,以default链接set与get时候,不需要加{}.
  • 上级子树,以default链接set与get时候,需要加{}.