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 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

这个控制节点被用在 你想中断之前的异步子节点从失败到成功

(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 sibling
        if( child_status == SUCCESS ) {
            // Suspend execution and return SUCCESS.
            HaltAllChildren();
            return SUCCESS;
        }
    }
    // all the children returned FAILURE. Return FAILURE too.
    HaltAllChildren();
    return FAILURE;

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值