Fallback

该节点家族在其他框架中被称为“选择器Selector”或“优先级Priority”。

他们的目的是尝试不同的策略,直到找到可行的策略。

它们具有以下规则:

  • tick第一个孩子之前,节点状态为RUNNING
  • 如果子节点返回FAILURE,则后备会tick下一个节点。
  • 如果最后一个子节点也返回FAILURE,则所有子节点都将暂停,并且序列将返回FAILURE
  • 如果子节点返回SUCCESS,它将停止并返回SUCCESS。 所有的子节点都停止了。

当孩子返回RUNNING时,Fallback的两个版本的反应方式不同:

  • FallbackStar将返回RUNNING,并且下次对其进行tick时,它将在之前停止的那个节点上tick
  • 普通的旧Fallback会返回RUNNING,并且每次执行后都会重置下一个要执行的子级的索引。

Fallback

在此示例中,我们尝试不同的策略来打开大门。 首先(和一次)检查门是否打开。

// index is initialized to 0 in the constructor
status = 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

如果先前条件之一将其状态从FAILURE更改为SUCCESS,则当您想中断异步子项时,将使用此ControlNode:ReactiveFallback

在以下示例中,如果角色充分休息,则该角色最多可睡8个小时或更短的时间。

伪代码

// index is initialized to 0 in the constructor
status = RUNNING; for (int index=0; index < number_of_children; index++)
{
child_status = child[index]->tick(); if( child_status == RUNNING ) {
return RUNNING;
}
else if( child_status == FAILURE ) {
// continue the while loop
index++;
}
else if( child_status == SUCCESS ) {
// Suspend execution and return SUCCESS.
// At the next tick, index will be the same.
HaltAllChildren();
return SUCCESS;
}
}
// all the children returned FAILURE. Return FAILURE too.
index = 0;
HaltAllChildren();
return FAILURE;

原文

最新文章

  1. 创建URL为空的解决办法
  2. Wordpress模板制作、改造、设计
  3. Altium designer 小技巧
  4. 转 java 类 单例
  5. python 安装scrapy
  6. Yii 实现MySQL多库和读写分离
  7. 关于6410的sd卡和nandflash启动的区别
  8. Python mongoDB 的简单操作
  9. Webservice简单概念
  10. CSS3鼠标移入移出图片生成随机动画
  11. Foundation Data Structure
  12. 【工具】Spring项目转化Spring Web项目插件
  13. vue-cli项目使用mock数据的方法(借助express)
  14. 络谷AT941(水提高+)题解
  15. R语言绘图(FZ)
  16. 关于解决JetBrains 激活问题
  17. scala 模式匹配详解 2 scala里是怎么实现的?
  18. oracle分区的名称和值要一致
  19. vmware增加共享文件夹
  20. ios UI自动化测试学习笔记

热门文章

  1. Java集合 - 集合知识点总结概述
  2. BUAA_2019_OO_第一单元总结
  3. 微服务(三) Eureka注册中心和Ribbon负载均衡
  4. Noip模拟69 2021.10.5
  5. lib库无法加载的情况分析
  6. 零基础学习Linux必会的60个常用命令
  7. [LGP1866]编号
  8. 攻防世界 杂项14.Erik-Baleog-and-Olaf
  9. 攻防世界 杂项 3.神奇的Modbus
  10. C++ map操作——插入、查找、遍历