mirror of
https://github.com/gongxh0901/kunpocc-behaviortree.git
synced 2025-12-26 16:48:56 +00:00
修改节点注释,重写文档
This commit is contained in:
640
README.md
640
README.md
@@ -1,187 +1,539 @@
|
||||
# 行为树
|
||||
|
||||
一个轻量级、高性能的 TypeScript 行为树库,专为游戏AI和决策系统设计。
|
||||
> 一个简洁、高效的 TypeScript 行为树库。遵循"好品味"设计原则:简单数据结构,消除特殊情况,直接暴露问题。
|
||||
|
||||
[](https://badge.fury.io/js/kunpocc-behaviortree)
|
||||
[](https://opensource.org/licenses/ISC)
|
||||
|
||||
## 特性
|
||||
|
||||
- 🚀 **高性能**: 优化的节点执行机制,最小化运行时开销
|
||||
- 🎯 **类型安全**: 完整的 TypeScript 支持,严格的类型检查
|
||||
- 🧩 **模块化**: 清晰的节点类型体系,易于扩展
|
||||
- 🔄 **记忆节点**: 支持记忆型组合节点,优化复杂决策流程
|
||||
- 📦 **零依赖**: 不依赖任何第三方库
|
||||
- 🎮 **游戏优化**: 专为游戏场景优化的黑板系统和状态管理
|
||||
- 🎯 **简洁设计**: 零废话,直接解决问题
|
||||
- 🔧 **类型安全**: 完整 TypeScript 支持
|
||||
- 🚀 **高性能**: 优化的执行机制,最小开销
|
||||
- 🧠 **记忆节点**: 智能状态记忆,避免重复计算
|
||||
- 📦 **零依赖**: 纯净实现,无第三方依赖
|
||||
- 🔄 **状态管理**: 分层黑板系统,数据隔离清晰
|
||||
|
||||
## 安装
|
||||
## 快速开始
|
||||
|
||||
### 安装
|
||||
|
||||
```bash
|
||||
npm install kunpocc-behaviortree
|
||||
```
|
||||
|
||||
## 快速开始
|
||||
### 基础示例
|
||||
|
||||
```typescript
|
||||
import {
|
||||
BehaviorTree,
|
||||
Action,
|
||||
Condition,
|
||||
Sequence,
|
||||
Selector,
|
||||
Status
|
||||
BehaviorTree, Status, Action, Condition,
|
||||
Sequence, Selector
|
||||
} from 'kunpocc-behaviortree';
|
||||
|
||||
// 定义AI角色
|
||||
interface Character {
|
||||
// 定义实体
|
||||
interface Enemy {
|
||||
health: number;
|
||||
hasWeapon: boolean;
|
||||
position: { x: number, y: number };
|
||||
}
|
||||
|
||||
const enemy: Enemy = {
|
||||
health: 30,
|
||||
hasWeapon: true,
|
||||
position: { x: 100, y: 200 }
|
||||
};
|
||||
|
||||
// 创建行为树
|
||||
const tree = new BehaviorTree(enemy,
|
||||
new Selector(
|
||||
// 生命值低时逃跑
|
||||
new Sequence(
|
||||
new Condition((node) => {
|
||||
const entity = node.getEntity<Enemy>();
|
||||
return entity.health < 50;
|
||||
}),
|
||||
new Action((node) => {
|
||||
console.log("血量低,逃跑!");
|
||||
return Status.SUCCESS;
|
||||
})
|
||||
),
|
||||
// 否则攻击
|
||||
new Action((node) => {
|
||||
console.log("发起攻击!");
|
||||
return Status.SUCCESS;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
// 执行
|
||||
tree.tick(); // 输出: "血量低,逃跑!"
|
||||
```
|
||||
|
||||
## 核心概念
|
||||
|
||||
### 状态类型
|
||||
```typescript
|
||||
enum Status {
|
||||
SUCCESS, // 成功
|
||||
FAILURE, // 失败
|
||||
RUNNING // 运行中
|
||||
}
|
||||
```
|
||||
|
||||
### 节点类型
|
||||
- **组合节点**: 控制子节点执行逻辑(Sequence、Selector、Parallel等)
|
||||
- **装饰节点**: 修饰单个子节点(Inverter、Repeat、Limit等)
|
||||
- **叶子节点**: 执行具体逻辑(Action、Condition、Wait等)
|
||||
|
||||
## 节点详解
|
||||
|
||||
### 组合节点 (Composite)
|
||||
|
||||
#### Sequence - 顺序节点
|
||||
按顺序执行子节点,全部成功才成功:
|
||||
```typescript
|
||||
new Sequence(
|
||||
checkAmmo, // 检查弹药
|
||||
aim, // 瞄准
|
||||
shoot // 射击
|
||||
)
|
||||
// 只有全部成功才返回SUCCESS
|
||||
```
|
||||
|
||||
#### Selector - 选择节点
|
||||
选择第一个成功的子节点:
|
||||
```typescript
|
||||
new Selector(
|
||||
tryMeleeAttack, // 尝试近战
|
||||
tryRangedAttack, // 尝试远程
|
||||
retreat // 撤退
|
||||
)
|
||||
// 任一成功就返回SUCCESS
|
||||
```
|
||||
|
||||
#### Parallel - 并行节点
|
||||
同时执行所有子节点,全部成功才成功:
|
||||
```typescript
|
||||
new Parallel(
|
||||
moveToTarget, // 移动到目标
|
||||
playAnimation, // 播放动画
|
||||
updateUI // 更新UI
|
||||
)
|
||||
// 任一失败返回FAILURE,有RUNNING返回RUNNING,全部SUCCESS才返回SUCCESS
|
||||
```
|
||||
|
||||
#### ParallelAnySuccess - 并行任一成功
|
||||
同时执行所有子节点,任一成功就成功:
|
||||
```typescript
|
||||
new ParallelAnySuccess(
|
||||
findCover, // 寻找掩体
|
||||
callForHelp, // 呼叫支援
|
||||
counterAttack // 反击
|
||||
)
|
||||
// 任一SUCCESS就返回SUCCESS
|
||||
```
|
||||
|
||||
#### Memory节点 - 状态记忆
|
||||
记忆节点会记住上次执行位置,避免重复执行:
|
||||
|
||||
```typescript
|
||||
// MemSequence - 记忆顺序节点
|
||||
new MemSequence(
|
||||
longTask1, // 第一次:SUCCESS,继续下一个
|
||||
longTask2, // 第一次:RUNNING,记住这个位置; 第二次:从longTask2开始继续执行
|
||||
longTask3
|
||||
)
|
||||
|
||||
// MemSelector - 记忆选择节点
|
||||
new MemSelector(
|
||||
expensiveCheck1, // 第一次:FAILURE,继续下一个
|
||||
expensiveCheck2, // 第一次:RUNNING,记住这个位置; 第二次:从expensiveCheck2开始执行
|
||||
fallback // 如果前面都是FAILURE才会执行到这里
|
||||
)
|
||||
```
|
||||
|
||||
#### RandomSelector - 随机选择
|
||||
随机选择一个子节点执行:
|
||||
```typescript
|
||||
new RandomSelector(
|
||||
idleBehavior1,
|
||||
idleBehavior2,
|
||||
idleBehavior3
|
||||
)
|
||||
```
|
||||
|
||||
### 装饰节点 (Decorator)
|
||||
|
||||
#### Inverter - 反转节点
|
||||
反转子节点的成功/失败状态:
|
||||
```typescript
|
||||
new Inverter(
|
||||
new Condition((node) => {
|
||||
const enemy = node.getEntity<Enemy>();
|
||||
return enemy.isAlive;
|
||||
})
|
||||
) // 敌人死亡时返回SUCCESS
|
||||
```
|
||||
|
||||
#### Repeat - 重复节点
|
||||
重复执行子节点指定次数:
|
||||
```typescript
|
||||
new Repeat(
|
||||
new Action((node) => {
|
||||
console.log("射击");
|
||||
return Status.SUCCESS;
|
||||
}),
|
||||
3 // 射击3次
|
||||
)
|
||||
```
|
||||
|
||||
#### RepeatUntilSuccess - 重复直到成功
|
||||
```typescript
|
||||
new RepeatUntilSuccess(
|
||||
new Action((node) => {
|
||||
console.log("尝试开门");
|
||||
return Math.random() > 0.5 ? Status.SUCCESS : Status.FAILURE;
|
||||
}),
|
||||
5 // 最多尝试5次
|
||||
)
|
||||
```
|
||||
|
||||
#### RepeatUntilFailure - 重复直到失败
|
||||
```typescript
|
||||
new RepeatUntilFailure(
|
||||
new Action((node) => {
|
||||
console.log("收集资源");
|
||||
return Status.SUCCESS; // 持续收集直到失败
|
||||
}),
|
||||
10 // 最多收集10次
|
||||
)
|
||||
```
|
||||
|
||||
#### LimitTime - 时间限制
|
||||
```typescript
|
||||
new LimitTime(
|
||||
new Action((node) => {
|
||||
console.log("执行复杂计算");
|
||||
return Status.SUCCESS;
|
||||
}),
|
||||
2.0 // 最多执行2秒
|
||||
)
|
||||
```
|
||||
|
||||
#### LimitTicks - 次数限制
|
||||
```typescript
|
||||
new LimitTicks(
|
||||
new Action((node) => {
|
||||
console.log("尝试操作");
|
||||
return Status.SUCCESS;
|
||||
}),
|
||||
5 // 最多执行5次
|
||||
)
|
||||
```
|
||||
|
||||
### 叶子节点 (Leaf)
|
||||
|
||||
#### Action - 动作节点
|
||||
执行自定义逻辑:
|
||||
```typescript
|
||||
new Action((node) => {
|
||||
// 直接获取实体
|
||||
const target = node.getEntity<Character>();
|
||||
|
||||
// 访问黑板数据
|
||||
const ammo = node.get<number>('ammo');
|
||||
|
||||
if (target && ammo > 0) {
|
||||
console.log("攻击目标");
|
||||
node.set('ammo', ammo - 1);
|
||||
return Status.SUCCESS;
|
||||
}
|
||||
return Status.FAILURE;
|
||||
})
|
||||
```
|
||||
|
||||
#### Condition - 条件节点
|
||||
检查条件:
|
||||
```typescript
|
||||
new Condition((node) => {
|
||||
const player = node.getEntity<Player>();
|
||||
const health = player.health;
|
||||
return health > 50; // true->SUCCESS, false->FAILURE
|
||||
})
|
||||
```
|
||||
|
||||
#### WaitTime - 时间等待
|
||||
```typescript
|
||||
new WaitTime(2.5) // 等待2.5秒
|
||||
```
|
||||
|
||||
#### WaitTicks - 帧数等待
|
||||
```typescript
|
||||
new WaitTicks(60) // 等待60帧
|
||||
```
|
||||
|
||||
## 黑板系统
|
||||
|
||||
黑板系统提供分层数据存储,支持数据隔离和查找链:
|
||||
|
||||
```typescript
|
||||
// 在节点中使用黑板
|
||||
new Action((node) => {
|
||||
// 直接获取实体
|
||||
const entity = node.getEntity<Character>();
|
||||
|
||||
// 本地数据(仅当前节点可见)
|
||||
node.set('local_count', 1);
|
||||
const count = node.get<number>('local_count');
|
||||
|
||||
// 树级数据(整棵树可见)
|
||||
node.setRoot('tree_data', 'shared');
|
||||
const shared = node.getRoot<string>('tree_data');
|
||||
|
||||
// 全局数据(所有树可见)
|
||||
node.setGlobal('global_config', config);
|
||||
const config = node.getGlobal<Config>('global_config');
|
||||
|
||||
return Status.SUCCESS;
|
||||
})
|
||||
```
|
||||
|
||||
### 数据查找链
|
||||
黑板数据按以下顺序查找:
|
||||
1. 当前节点的本地黑板
|
||||
2. 父节点的黑板
|
||||
3. 递归向上查找到根节点
|
||||
|
||||
### Memory节点的数据隔离
|
||||
Memory节点会创建独立的子黑板,确保状态隔离:
|
||||
```typescript
|
||||
const mem1 = new MemSequence(/* ... */);
|
||||
const mem2 = new MemSequence(/* ... */);
|
||||
// mem1 和 mem2 的记忆状态完全独立
|
||||
```
|
||||
|
||||
## 完整示例
|
||||
|
||||
```typescript
|
||||
import {
|
||||
BehaviorTree, Status, Action, Condition,
|
||||
Sequence, Selector, MemSelector, Parallel,
|
||||
Inverter, RepeatUntilSuccess, LimitTime
|
||||
} from 'kunpocc-behaviortree';
|
||||
|
||||
interface Character {
|
||||
health: number;
|
||||
mana: number;
|
||||
hasWeapon: boolean;
|
||||
isInCombat: boolean;
|
||||
position: { x: number, y: number };
|
||||
}
|
||||
|
||||
const character: Character = {
|
||||
health: 80,
|
||||
hasWeapon: true
|
||||
mana: 50,
|
||||
hasWeapon: true,
|
||||
isInCombat: false,
|
||||
position: { x: 0, y: 0 }
|
||||
};
|
||||
|
||||
// 创建条件节点
|
||||
const isHealthLow = new Condition((char: Character) => char.health < 30);
|
||||
const hasWeapon = new Condition((char: Character) => char.hasWeapon);
|
||||
|
||||
// 创建行动节点
|
||||
const flee = new Action(() => {
|
||||
console.log("逃跑!");
|
||||
return Status.SUCCESS;
|
||||
});
|
||||
|
||||
const attack = new Action(() => {
|
||||
console.log("攻击!");
|
||||
return Status.SUCCESS;
|
||||
});
|
||||
|
||||
// 构建行为树:生命值低时逃跑,否则攻击
|
||||
const tree = new BehaviorTree(character,
|
||||
// 构建复杂行为树
|
||||
const behaviorTree = new BehaviorTree(character,
|
||||
new Selector(
|
||||
new Sequence(isHealthLow, flee),
|
||||
new Sequence(hasWeapon, attack)
|
||||
// 战斗行为
|
||||
new Sequence(
|
||||
new Condition((node) => {
|
||||
const char = node.getEntity<Character>();
|
||||
return char.isInCombat;
|
||||
}),
|
||||
new Selector(
|
||||
// 生命值低时治疗
|
||||
new Sequence(
|
||||
new Condition((node) => {
|
||||
const char = node.getEntity<Character>();
|
||||
return char.health < 30;
|
||||
}),
|
||||
new RepeatUntilSuccess(
|
||||
new Action((node) => {
|
||||
const char = node.getEntity<Character>();
|
||||
if (char.mana >= 10) {
|
||||
char.health += 20;
|
||||
char.mana -= 10;
|
||||
console.log("治疗完成");
|
||||
return Status.SUCCESS;
|
||||
}
|
||||
return Status.FAILURE;
|
||||
}),
|
||||
3 // 最多尝试3次
|
||||
)
|
||||
),
|
||||
// 正常攻击
|
||||
new Sequence(
|
||||
new Condition((node) => {
|
||||
const char = node.getEntity<Character>();
|
||||
return char.hasWeapon;
|
||||
}),
|
||||
new LimitTime(
|
||||
new Action((node) => {
|
||||
console.log("发起攻击");
|
||||
return Status.SUCCESS;
|
||||
}),
|
||||
1.0 // 攻击最多1秒
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
// 非战斗行为 - 巡逻
|
||||
new MemSelector(
|
||||
new Action((node) => {
|
||||
console.log("巡逻点A");
|
||||
return Status.SUCCESS;
|
||||
}),
|
||||
new Action((node) => {
|
||||
console.log("巡逻点B");
|
||||
return Status.SUCCESS;
|
||||
}),
|
||||
new Action((node) => {
|
||||
console.log("巡逻点C");
|
||||
return Status.SUCCESS;
|
||||
})
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
// 执行行为树
|
||||
tree.tick(); // 输出: "攻击!"
|
||||
console.log("=== 执行行为树 ===");
|
||||
behaviorTree.tick(); // 输出: "巡逻点A"
|
||||
|
||||
// 进入战斗状态
|
||||
character.isInCombat = true;
|
||||
character.health = 20; // 低血量
|
||||
|
||||
behaviorTree.tick(); // 输出: "治疗完成"
|
||||
```
|
||||
|
||||
#### 基本概念
|
||||
## 最佳实践
|
||||
|
||||
1. 节点状态
|
||||
### 1. 节点设计原则
|
||||
- **单一职责**: 每个节点只做一件事
|
||||
- **状态明确**: 明确定义SUCCESS/FAILURE/RUNNING的含义
|
||||
- **避免副作用**: 尽量避免节点间的隐式依赖
|
||||
|
||||
### 2. 性能优化
|
||||
```typescript
|
||||
// ✅ 好的做法 - 使用记忆节点避免重复计算
|
||||
new MemSelector(
|
||||
expensivePathfinding, // 复杂寻路只计算一次
|
||||
fallbackBehavior
|
||||
)
|
||||
|
||||
// ❌ 避免 - 每次都重新计算
|
||||
new Selector(
|
||||
expensivePathfinding, // 每次tick都会重新计算
|
||||
fallbackBehavior
|
||||
)
|
||||
```
|
||||
|
||||
### 3. 黑板使用
|
||||
```typescript
|
||||
// ✅ 好的做法 - 合理使用数据层级
|
||||
new Action((node) => {
|
||||
// 获取实体
|
||||
const player = node.getEntity<Player>();
|
||||
|
||||
// 临时数据用本地黑板
|
||||
node.set('temp_result', calculation());
|
||||
|
||||
// 共享数据用树级黑板
|
||||
node.setRoot('current_target', target);
|
||||
|
||||
// 配置数据用全局黑板
|
||||
node.setGlobal('game_config', config);
|
||||
})
|
||||
```
|
||||
|
||||
### 4. 错误处理
|
||||
```typescript
|
||||
// ✅ 明确的错误处理
|
||||
new Action((node) => {
|
||||
try {
|
||||
const result = riskyOperation();
|
||||
return result ? Status.SUCCESS : Status.FAILURE;
|
||||
} catch (error) {
|
||||
console.error('Operation failed:', error);
|
||||
return Status.FAILURE;
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
## 测试覆盖
|
||||
|
||||
本库包含全面的测试用例,覆盖:
|
||||
- ✅ 17种节点类型 (100%覆盖)
|
||||
- ✅ Memory节点状态管理
|
||||
- ✅ 黑板数据隔离
|
||||
- ✅ 边界条件处理
|
||||
- ✅ 复杂嵌套场景
|
||||
|
||||
运行测试:
|
||||
```bash
|
||||
npm test
|
||||
```
|
||||
|
||||
## API 参考
|
||||
|
||||
### 核心类
|
||||
|
||||
#### `BehaviorTree<T>`
|
||||
```typescript
|
||||
constructor(entity: T, root: IBTNode)
|
||||
tick(): Status // 执行一次行为树
|
||||
reset(): void // 重置所有状态
|
||||
```
|
||||
|
||||
#### `Status`
|
||||
```typescript
|
||||
enum Status {
|
||||
SUCCESS, // 成功
|
||||
FAILURE, // 失败
|
||||
RUNNING // 运行中
|
||||
SUCCESS = 0,
|
||||
FAILURE = 1,
|
||||
RUNNING = 2
|
||||
}
|
||||
```
|
||||
|
||||
2. 节点类型
|
||||
- **动作节点 (Action)**:执行具体行为的叶子节点
|
||||
- **组合节点 (Composite)**:控制子节点执行顺序的节点
|
||||
- **条件节点 (Condition)**:判断条件的节点
|
||||
- **装饰节点 (Decorator)**:修饰其他节点行为的节点
|
||||
### 节点接口
|
||||
```typescript
|
||||
interface IBTNode {
|
||||
readonly children: IBTNode[];
|
||||
// 节点黑板
|
||||
local: IBlackboard;
|
||||
tick(): Status;
|
||||
|
||||
// 优先写入自己的黑板数据, 如果没有则写入父节点的黑板数据
|
||||
set<T>(key: string, value: T): void;
|
||||
get<T>(key: string): T;
|
||||
// 写入树根节点的黑板数据
|
||||
setRoot<T>(key: string, value: T): void;
|
||||
getRoot<T>(key: string): T;
|
||||
// 写入全局黑板数据
|
||||
setGlobal<T>(key: string, value: T): void;
|
||||
getGlobal<T>(key: string): T;
|
||||
|
||||
// 实体访问
|
||||
getEntity<T>(): T;
|
||||
}
|
||||
```
|
||||
|
||||
#### 常用节点
|
||||
## 许可证
|
||||
|
||||
1. 组合节点
|
||||
ISC License - 详见 [LICENSE](LICENSE) 文件
|
||||
|
||||
```typescript
|
||||
// 顺序节点:按顺序执行所有子节点,直到遇到失败或运行中的节点
|
||||
new Sequence(childNode1, childNode2, childNode3);
|
||||
|
||||
// 选择节点:选择第一个成功或运行中的子节点
|
||||
new Selector(childNode1, childNode2, childNode3);
|
||||
|
||||
// 并行节点:同时执行所有子节点,全部成功才成功
|
||||
new Parallel(childNode1, childNode2, childNode3);
|
||||
|
||||
// 并行任一成功节点:同时执行所有子节点,任一成功即成功
|
||||
new ParallelAnySuccess(childNode1, childNode2, childNode3);
|
||||
|
||||
// 记忆顺序节点:记住上次执行的位置
|
||||
new MemSequence(childNode1, childNode2, childNode3);
|
||||
|
||||
// 记忆选择节点:记住上次执行的位置
|
||||
new MemSelector(childNode1, childNode2, childNode3);
|
||||
|
||||
// 随机选择节点:随机选择一个子节点执行
|
||||
new RandomSelector(childNode1, childNode2, childNode3);
|
||||
```
|
||||
## 贡献
|
||||
|
||||
2. 动作节点
|
||||
欢迎提交 Issue 和 Pull Request。请确保:
|
||||
1. 代码风格一致
|
||||
2. 添加适当的测试
|
||||
3. 更新相关文档
|
||||
|
||||
```typescript
|
||||
// 行动节点 - 返回指定状态
|
||||
new Action(() => {
|
||||
console.log("执行动作");
|
||||
return Status.SUCCESS; // 或 Status.FAILURE, Status.RUNNING
|
||||
});
|
||||
|
||||
// 条件节点 - 检查条件返回成功或失败
|
||||
new Condition((subject) => {
|
||||
return subject.health > 50; // 返回 true 表示成功,false 表示失败
|
||||
});
|
||||
|
||||
// 等待节点
|
||||
new WaitTime(2); // 等待2秒
|
||||
new WaitTicks(5); // 等待5个tick
|
||||
```
|
||||
---
|
||||
|
||||
3. 装饰节点
|
||||
|
||||
```typescript
|
||||
// 反转节点 - 反转子节点的成功/失败状态
|
||||
new Inverter(childNode);
|
||||
|
||||
// 重复节点 - 重复执行子节点指定次数
|
||||
new Repeat(childNode, 3);
|
||||
|
||||
// 重复直到失败 - 重复执行直到子节点失败
|
||||
new RepeatUntilFailure(childNode, 5);
|
||||
|
||||
// 重复直到成功 - 重复执行直到子节点成功
|
||||
new RepeatUntilSuccess(childNode, 5);
|
||||
|
||||
// 时间限制节点 - 限制子节点执行时间
|
||||
new LimitTime(childNode, 5); // 5秒
|
||||
|
||||
// 次数限制节点 - 限制子节点执行次数
|
||||
new LimitTimes(childNode, 3);
|
||||
```
|
||||
|
||||
4. 使用黑板共享数据
|
||||
|
||||
```typescript
|
||||
// 在节点中使用黑板
|
||||
class CustomAction extends BTNode {
|
||||
tick: Status {
|
||||
// 获取数据 - 使用节点实例作为命名空间
|
||||
const data = tree.blackboard.get<string>("key", this);
|
||||
|
||||
// 设置数据 - 使用节点实例作为命名空间
|
||||
tree.blackboard.set("key", "value", this);
|
||||
|
||||
return Status.SUCCESS;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
#### 注意事项
|
||||
|
||||
1. 节点状态说明:
|
||||
- `SUCCESS`:节点执行成功
|
||||
- `FAILURE`:节点执行失败
|
||||
- `RUNNING`:节点正在执行中
|
||||
2. 组合节点特性:
|
||||
- `Sequence`:所有子节点返回 SUCCESS 才返回 SUCCESS
|
||||
- `Selector`:任一子节点返回 SUCCESS 就返回 SUCCESS
|
||||
- `Parallel`:并行执行所有子节点
|
||||
- `MemSequence/MemSelector`:会记住上次执行位置
|
||||
3. 性能优化:
|
||||
- 使用黑板共享数据,避免重复计算
|
||||
- 合理使用记忆节点,减少重复执行
|
||||
- 控制行为树的深度,避免过于复杂
|
||||
*"好的程序员关心数据结构,而不是代码。"* - 这个库遵循简洁设计原则,专注于解决实际问题。
|
||||
Reference in New Issue
Block a user