mirror of
https://github.com/gongxh0901/kunpocc-behaviortree.git
synced 2025-12-26 16:48:56 +00:00
修改节点注释,重写文档
This commit is contained in:
@@ -2,44 +2,50 @@ import { Status } from "../header";
|
||||
import { Composite, MemoryComposite } from "./AbstractNodes";
|
||||
|
||||
/**
|
||||
* 记忆选择节点
|
||||
* 选择不为 FAILURE 的节点,记住上次运行的子节点位置
|
||||
* 任意一个Child Node返回不为 FAILURE, 本Node向自己的Parent Node也返回Child Node状态
|
||||
* 记忆选择节点 从上到下执行
|
||||
* 遇到 FAILURE 继续下一个
|
||||
* 遇到 SUCCESS 返回 SUCCESS 下次重新开始
|
||||
*
|
||||
* 遇到 RUNNING 返回 RUNNING 下次从该节点开始
|
||||
*/
|
||||
export class MemSelector extends MemoryComposite {
|
||||
public tick(): Status {
|
||||
let index = this.get<number>(`__nMemoryRunningIndex`);
|
||||
for (let i = index; i < this.children.length; i++) {
|
||||
let status = this.children[i]!._execute();
|
||||
if (status !== Status.FAILURE) {
|
||||
if (status === Status.RUNNING) {
|
||||
this.set(`__nMemoryRunningIndex`, i);
|
||||
}
|
||||
if (status === Status.FAILURE) {
|
||||
continue;
|
||||
}
|
||||
if (status === Status.SUCCESS) {
|
||||
return status;
|
||||
}
|
||||
this.set(`__nMemoryRunningIndex`, i);
|
||||
return Status.RUNNING;
|
||||
}
|
||||
return Status.FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 记忆顺序节点
|
||||
* 如果上次执行到 RUNNING 的节点, 下次进入节点后, 直接从 RUNNING 节点开始
|
||||
* 遇到 SUCCESS 或者 FAILURE 停止迭代
|
||||
* 任意一个Child Node返回不为 SUCCESS, 本Node向自己的Parent Node也返回Child Node状态
|
||||
* 所有节点都返回 SUCCESS, 本节点才返回 SUCCESS
|
||||
* 记忆顺序节点 从上到下执行
|
||||
* 遇到 SUCCESS 继续下一个
|
||||
* 遇到 FAILURE 停止迭代 返回 FAILURE 下次重新开始
|
||||
*
|
||||
* 遇到 RUNNING 返回 RUNNING 下次从该节点开始
|
||||
*/
|
||||
export class MemSequence extends MemoryComposite {
|
||||
public tick(): Status {
|
||||
let index = this.get<number>(`__nMemoryRunningIndex`);
|
||||
for (let i = index; i < this.children.length; i++) {
|
||||
let status = this.children[i]!._execute();
|
||||
if (status !== Status.SUCCESS) {
|
||||
if (status === Status.RUNNING) {
|
||||
this.set(`__nMemoryRunningIndex`, i);
|
||||
}
|
||||
return status;
|
||||
if (status === Status.SUCCESS) {
|
||||
continue;
|
||||
}
|
||||
if (status === Status.FAILURE) {
|
||||
return Status.FAILURE;
|
||||
}
|
||||
this.set(`__nMemoryRunningIndex`, i);
|
||||
return Status.RUNNING;
|
||||
}
|
||||
return Status.SUCCESS;
|
||||
}
|
||||
@@ -47,7 +53,8 @@ export class MemSequence extends MemoryComposite {
|
||||
|
||||
/**
|
||||
* 随机选择节点
|
||||
* 从Child Node中随机选择一个执行
|
||||
* 随机选择一个子节点执行
|
||||
* 返回子节点状态
|
||||
*/
|
||||
export class RandomSelector extends Composite {
|
||||
public tick(): Status {
|
||||
@@ -62,9 +69,9 @@ export class RandomSelector extends Composite {
|
||||
}
|
||||
|
||||
/**
|
||||
* 选择节点,选择不为 FAILURE 的节点
|
||||
* 当执行本Node时,它将从begin到end迭代执行自己的Child Node:
|
||||
* 如遇到一个Child Node执行后返回 SUCCESS 或者 RUNNING,那停止迭代,本Node向自己的Parent Node也返回 SUCCESS 或 RUNNING
|
||||
* 选择节点 从上到下执行
|
||||
* 返回第一个不为 FAILURE 的子节点状态
|
||||
* 否则返回 FAILURE
|
||||
*/
|
||||
export class Selector extends Composite {
|
||||
public tick(): Status {
|
||||
@@ -79,29 +86,26 @@ export class Selector extends Composite {
|
||||
}
|
||||
|
||||
/**
|
||||
* 顺序节点
|
||||
* 当执行本类型Node时,它将从begin到end迭代执行自己的Child Node:
|
||||
* 遇到 FAILURE 或 RUNNING, 那停止迭代,返回FAILURE 或 RUNNING
|
||||
* 所有节点都返回 SUCCESS, 本节点才返回 SUCCESS
|
||||
* 顺序节点 从上到下执行
|
||||
* 遇到 SUCCESS 继续下一个
|
||||
* 否则返回子节点状态
|
||||
*/
|
||||
export class Sequence extends Composite {
|
||||
public tick(): Status {
|
||||
for (let i = 0; i < this.children.length; i++) {
|
||||
let status = this.children[i]!._execute();
|
||||
if (status !== Status.SUCCESS) {
|
||||
return status;
|
||||
if (status === Status.SUCCESS) {
|
||||
continue;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
return Status.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 并行节点 每次进入全部执行一遍
|
||||
* 它将从begin到end迭代执行自己的Child Node:
|
||||
* 1. 任意子节点返回 FAILURE, 返回 FAILURE
|
||||
* 2. 否则 任意子节点返回 RUNNING, 返回 RUNNING
|
||||
* 3. 全部成功, 才返回 SUCCESS
|
||||
* 并行节点 从上到下执行 全部执行一遍
|
||||
* 返回优先级 FAILURE > RUNNING > SUCCESS
|
||||
*/
|
||||
export class Parallel extends Composite {
|
||||
public tick(): Status {
|
||||
@@ -110,11 +114,8 @@ export class Parallel extends Composite {
|
||||
let status = this.children[i]!._execute();
|
||||
if (result === Status.FAILURE || status === Status.FAILURE) {
|
||||
result = Status.FAILURE;
|
||||
continue;
|
||||
}
|
||||
if (status === Status.RUNNING) {
|
||||
} else if (status === Status.RUNNING) {
|
||||
result = Status.RUNNING;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@@ -122,24 +123,18 @@ export class Parallel extends Composite {
|
||||
}
|
||||
|
||||
/**
|
||||
* 并行节点 每次进入全部重新执行一遍
|
||||
* 它将从begin到end迭代执行自己的Child Node:
|
||||
* 1. 任意子节点返回 SUCCESS, 返回 SUCCESS
|
||||
* 2. 否则, 任意子节点返回 FAILURE, 返回 FAILURE
|
||||
* 否则返回 RUNNING
|
||||
* 并行节点 从上到下执行 全部执行一遍
|
||||
* 返回优先级 SUCCESS > RUNNING > FAILURE
|
||||
*/
|
||||
export class ParallelAnySuccess extends Composite {
|
||||
public tick(): Status {
|
||||
let result = Status.RUNNING;
|
||||
let result = Status.FAILURE;
|
||||
for (let i = 0; i < this.children.length; i++) {
|
||||
let status = this.children[i]!._execute();
|
||||
if (result === Status.SUCCESS || status === Status.SUCCESS) {
|
||||
result = Status.SUCCESS;
|
||||
continue;
|
||||
}
|
||||
if (status === Status.FAILURE) {
|
||||
result = Status.FAILURE;
|
||||
continue;
|
||||
} else if (status === Status.RUNNING) {
|
||||
result = Status.RUNNING;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user