BehaviorTree.CPP行为树学习:Sequences node

Sequences node

序列节点,是所有子节点都返回成功,序列节点为成功,如果有其中一个子节点返回失败,则序列为失败

【原文链接】Sequence Nodes - BehaviorTree.CPP

(A Sequence ticks all its children as long as they return SUCCESS. If any child returns FAILURE, the sequence is aborted)

行为树提供以下类型的节点

  • Sequence
  • SequenceStar
  • ReactiveSequence

它们有以下共同特点:

  • 在tick第一个子节点,序列节点状态为Running。(Before ticking the first child, the node status becomes RUNNING.)
  • 如果一个子节点返回成功,则继续ticks下一个子节点
  • 如果最后一子个节点返回成功,并且所有子节点都执行完了,序列节点会返回成功(If the

last child returns SUCCESS too, all the children are ‎停止‎ and the sequence returns SUCCESS.)

这三种类型的区别如下

"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.)

Sequence

按顺序执行,任何一个子节点失败都会重新开始 

伪代码

    status = RUNNING;
    // _index is a private member
    while(_index < number_of_children)
    {
        child_status = child[_index]->tick();
        if( child_status == SUCCESS ) {
            _index++;
        }
        else if( child_status == RUNNING ) {
            // keep same index
            return RUNNING;
        }
        else if( child_status == FAILURE ) {
            HaltAllChildren();
            _index = 0;
            return FAILURE;
        }
    }
    // all the children returned success. Return SUCCESS too.
    HaltAllChildren();
    _index = 0;
    return SUCCESS;

ReactiveSequence

此节点特别适用于连续检查条件;但是用户在使用异步子节点时也应该小心,以确保它们不会比预期的更频繁地被勾选。(This node is particularly useful to continuously check Conditions; but the user should also be careful when using asynchronous children, to be sure that they are not ticked more often that expected.)

例子,看见敌人 接近敌人

接近敌人(ApproachEnemy)是一个异步操作,它会返回running,知道它最终完成

(ApproachEnemy is an asynchronous action that returns RUNNING until it is, eventually, completed.)

条件 敌人是否可见,可能会被调用很多次,如果它变成失败,则接近敌人

(The condition isEnemyVisible will be called many times and, if it becomes false (i,e, "FAILURE"), is halted.ApproachEnemy)

伪代码

 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 ) {
            HaltAllChildren();
            return FAILURE;
        }
    }
    // all the children returned success. Return SUCCESS too.
    HaltAllChildren();
    return SUCCESS;

SequenceStar

当返回成功的子节点不希望再次执行时,可以使用这个node。例如在多点任务巡航过程

去A 成功,去B失败,下次tick时不会再去A

(On the other hand, isBatteryOK must be checked at every tick, for this reason its parent must be a .ReactiveSequence)

伪代码

    status = RUNNING;
    // _index is a private member
    while( index < number_of_children)
    {
        child_status = child[index]->tick();
        if( child_status == SUCCESS ) {
            _index++;
        }
        else if( child_status == RUNNING || 
                 child_status == FAILURE ) 
        {
            // keep same index
            return child_status;
        }
    }
    // all the children returned success. Return SUCCESS too.
    HaltAllChildren();
    _index = 0;
    return SUCCESS;

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
C:\Users\admin\Desktop\前端开发\Node.js\day6\code\api_server\node_modules\mysql\lib\protocol\Parser.js:437 throw err; // Rethrow non-MySQL errors ^ Error: secretOrPrivateKey must have a value at module.exports [as sign] (C:\Users\admin\Desktop\前端开发\Node.js\day6\code\api_server\node_modules\jsonwebtoken\sign.js:107:20) at Query.<anonymous> (C:\Users\admin\Desktop\前端开发\Node.js\day6\code\api_server\router_handler\2user.js:49:26) at Query.<anonymous> (C:\Users\admin\Desktop\前端开发\Node.js\day6\code\api_server\node_modules\mysql\lib\Connection.js:526:10) at Query._callback (C:\Users\admin\Desktop\前端开发\Node.js\day6\code\api_server\node_modules\mysql\lib\Connection.js:488:16) at Sequence.end (C:\Users\admin\Desktop\前端开发\Node.js\day6\code\api_server\node_modules\mysql\lib\protocol\sequences\Sequence.js:83:24) at Query._handleFinalResultPacket (C:\Users\admin\Desktop\前端开发\Node.js\day6\code\api_server\node_modules\mysql\lib\protocol\sequences\Query.js:149:8) at Query.EofPacket (C:\Users\admin\Desktop\前端开发\Node.js\day6\code\api_server\node_modules\mysql\lib\protocol\sequences\Query.js:133:8) at Protocol._parsePacket (C:\Users\admin\Desktop\前端开发\Node.js\day6\code\api_server\node_modules\mysql\lib\protocol\Protocol.js:291:23) at Parser._parsePacket (C:\Users\admin\Desktop\前端开发\Node.js\day6\code\api_server\node_modules\mysql\lib\protocol\Parser.js:433:10) at Parser.write (C:\Users\admin\Desktop\前端开发\Node.js\day6\code\api_server\node_modules\mysql\lib\protocol\Parser.js:43:10) Node.js v18.12.1
06-08

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值