本文主要是介绍BehaviorTree.CPP行为树学习:ReactiveFallback,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
ReactiveFallback
在其他框架中,这一系列节点称为“选择器”或“优先级”。
他们的目的是尝试不同的策略,直到我们找到一个“有效”的策略。
目前框架提供两种节点:
- Fallback
- ReactiveFallback
它们遵循以下规则
- 在tick第一个子节点之前,节点状态变为RUNNING
- 如果一个子节点返回失败,fallback将会tick下一个子节点
- 若最后一个子节点也返回失败(所有的子节点都返回失败),fallback返回失败
- 如果一个子节点返回成功,fallback将会返回成功,并且其他子节点终止(halted)
两种之间的区别:
"Restart":重启从序列节点的第一个子节点开始(means that the entire sequence is restarted from the first child of the list.)
"Tick again" :下次tick时,之前已经返回成功的子节点不会被tick。(means that the next time the sequence is ticked, the same child is ticked again. Previous sibling, which returned SUCCESS already, are not ticked again.)
【原文链接】Fallback Nodes - BehaviorTree.CPP
Fallback
例子
尝试不同策略开门。如果门开,则返回成功,否则执行开门?解锁?砸碎门
伪代码
// index is initialized to 0 in the constructorstatus = RUNNING;while( _index < number_of_children ){child_status = child[index]->tick();if( child_status == RUNNING ) {// Suspend execution and return RUNNING.// At the next tick, _index will be the same.return RUNNING;}else if( child_status == FAILURE ) {// continue the while loop_index++;}else if( child_status == SUCCESS ) {// Suspend execution and return SUCCESS.HaltAllChildren();_index = 0;return SUCCESS;}}// all the children returned FAILURE. Return FAILURE too.index = 0;HaltAllChildren();return FAILURE;
ReactiveFallback
这个控制节点被用在 你想中断之前的异步子节点从失败到成功
(This ControlNode is used when you want to interrupt an asynchronous child if one of the previous Conditions changes its state from FAILURE to SUCCESS.)
是否精力充沛?
部署则休息8个小时,areYouRested超过八个小时会返回success,睡眠将被中断
(In the following example, the character will sleep up to 8 hours. If he/she has fully rested, then the node areYouRested? will return SUCCESS and the asynchronous nodes Timeout (8 hrs) and Sleep will be interrupted.)
伪代码
status = RUNNING;for (int index=0; index < number_of_children; index++){child_status = child[index]->tick();if( child_status == RUNNING ) {// Suspend all subsequent siblings and return RUNNING.HaltSubsequentSiblings();return RUNNING;}// if child_status == FAILURE, continue to tick next siblingif( child_status == SUCCESS ) {// Suspend execution and return SUCCESS.HaltAllChildren();return SUCCESS;}}// all the children returned FAILURE. Return FAILURE too.HaltAllChildren();return FAILURE;
这篇关于BehaviorTree.CPP行为树学习:ReactiveFallback的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!