PSBTree 行为树引擎
基于 C++ 和 Python 实现的高性能行为树引擎,支持顺序和并行执行模式,适用于机器人控制、游戏 AI 和自动化系统。
项目结构
.
├── src/ # 源代码目录
│ └── psbtree/ # 主包目录
│ ├── engine/ # 引擎实现(顺序和并行)
│ ├── nodes/ # 节点实现(动作、条件、控制、装饰器)
│ ├── plugins/ # 插件系统
│ └── utils/ # 工具函数
├── sample/ # 示例代码
├── tests/ # 测试代码
├── doc/ # 文档
├── source_cpp/ # C++ 源代码
├── dependencies/ # 依赖项
├── scripts/ # 构建脚本
├── pyproject.toml # 项目配置
├── setup.py # 安装脚本
└── README.md # 项目文档
核心功能
- 行为树引擎: 支持顺序和并行执行模式
- 节点系统: 提供丰富的节点类型(动作、条件、控制、装饰器)
- 高性能: 核心功能使用 C++ 实现,通过 Cython 与 Python 集成
- 授权系统: 内置授权验证机制
- 插件扩展: 支持通过插件系统扩展功能
快速开始
-
安装依赖:
pip install -r requirements.txt
-
安装包:
pip install .
-
设置授权码:
from psbtree import set_sk_code set_sk_code("您的授权码")
-
运行示例:
python sample/sequential_engine_sample.py
依赖管理
核心依赖包括:
loguru: 日志记录psdec: 授权验证opencv-python: 图像处理(示例中使用)
使用示例
顺序引擎示例
from psbtree.engine.sequential_engine import SequentialEngine
from psbtree.nodes import SimpleActionNode, TreeNode, NodeStatus
from psbtree import set_sk_code
# 设置授权码
set_sk_code("您的授权码")
# 创建顺序引擎
engine = SequentialEngine()
# 注册节点
engine.register_action_class(YourActionNode, "YourActionNode")
# 定义行为树XML
xml_text = """
<root BTCPP_format="4">
<BehaviorTree ID="MainTree">
<Sequence name="root_sequence">
<YourActionNode />
</Sequence>
</BehaviorTree>
</root>
"""
# 从XML创建行为树
engine.create_tree_from_text(xml_text)
# 运行行为树
status = engine.tick_once()
并行引擎示例
from psbtree.engine.parallel_engine import ParallelEngine
from psbtree.nodes import SimpleActionNode, TreeNode, NodeStatus
from psbtree import set_sk_code
# 设置授权码
set_sk_code("您的授权码")
# 创建并行引擎
engine = ParallelEngine()
# 注册节点
engine.register_action_class(YourActionNode, "YourActionNode")
# 定义多个行为树XML
xml_text_tree0 = """
<root BTCPP_format="4">
<BehaviorTree ID="Tree0">
<Sequence name="root_sequence">
<YourActionNode />
</Sequence>
</BehaviorTree>
</root>
"""
# 从XML创建行为树
tree_id0 = engine.create_tree_from_text(xml_text_tree0, "tree0")
# 运行行为树
status0 = engine.tick_once(tree_id0)
开发指南
- 使用
SimpleActionNode作为基类创建自定义节点 - 通过
ports静态变量定义节点的输入输出端口 - 实现
tick静态方法定义节点的行为 - 使用 XML 格式定义行为树结构
- 遵循行为树设计模式最佳实践
贡献
欢迎提交 PR 和 issue。请确保:
- 代码符合项目编码规范
- 包含必要的单元测试
- 更新相关文档
许可证
MIT License
Release files for psbtree 0.1.32
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
| File | Reset | |||
|---|---|---|---|---|
| psbtree-0.1.32-cp313-cp313-manylinux_2_28_x86_64.whl | CPython 3.13 | CPython 3.13 | Linux glibc 2.28+ x86-64 | Details |
| psbtree-0.1.32-cp312-cp312-manylinux_2_28_x86_64.whl | CPython 3.12 | CPython 3.12 | Linux glibc 2.28+ x86-64 | Details |
| psbtree-0.1.32-cp311-cp311-manylinux_2_28_x86_64.whl | CPython 3.11 | CPython 3.11 | Linux glibc 2.28+ x86-64 | Details |
| psbtree-0.1.32-cp310-cp310-manylinux_2_28_x86_64.whl | CPython 3.10 | CPython 3.10 | Linux glibc 2.28+ x86-64 | Details |
| psbtree-0.1.32-cp39-cp39-manylinux_2_28_x86_64.whl | CPython 3.9 | CPython 3.9 | Linux glibc 2.28+ x86-64 | Details |
Total release size: 53.9 MB
Release files / psbtree-0.1.32-cp313-cp313-manylinux_2_28_x86_64.whl
| Download URL | psbtree-0.1.32-cp313-cp313-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 11.0 MB |
| Tags | CPython 3.13 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
541595b382e6ef2e3728a42c4e510306987178ffe5b3e2a603d993ab16b22cf0
|
|
BLAKE2b-256 checksum How to use checksums |
f6cbe89b08e7487d61a7bb4e22e1d99816ff952171565abe7a9adb2c6b64e7e6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.2
|
Release files / psbtree-0.1.32-cp312-cp312-manylinux_2_28_x86_64.whl
| Download URL | psbtree-0.1.32-cp312-cp312-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 11.1 MB |
| Tags | CPython 3.12 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
6602afcf23949e6699d72530eb6e1d6819b075880082d21fadf43921e1723fb4
|
|
BLAKE2b-256 checksum How to use checksums |
059d2994204c4548dc6c2689fbddcf3c3dc5e95fe2a555c283e08befeb901da9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.2
|
Release files / psbtree-0.1.32-cp311-cp311-manylinux_2_28_x86_64.whl
| Download URL | psbtree-0.1.32-cp311-cp311-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 10.9 MB |
| Tags | CPython 3.11 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
38187d35091eea31ccf3557425819753ded14a632a1f92c4969735a98f2aeb07
|
|
BLAKE2b-256 checksum How to use checksums |
30998e14490626e346d218b9897e02fb8b52b34bd0df05b591675ca67d2157ae
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.2
|
Release files / psbtree-0.1.32-cp310-cp310-manylinux_2_28_x86_64.whl
| Download URL | psbtree-0.1.32-cp310-cp310-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 10.5 MB |
| Tags | CPython 3.10 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
e384a4a5e8c44f9cfead590ee1da4c0ca7f6a1d87f28971a7d249536f2ca773d
|
|
BLAKE2b-256 checksum How to use checksums |
72277b1581ab69a3db2f90132ae3f0605c13bdbd2b4241407394de13270e46d4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.2
|
Release files / psbtree-0.1.32-cp39-cp39-manylinux_2_28_x86_64.whl
| Download URL | psbtree-0.1.32-cp39-cp39-manylinux_2_28_x86_64.whl |
|---|---|
| Size | 10.4 MB |
| Tags | CPython 3.9 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
0169485a9ed958cc3ac42514ec46ddc4ae53ff1f26c0b34eb5302f1957dabed4
|
|
BLAKE2b-256 checksum How to use checksums |
3d5a5ee3b298d163b633d140314c6675cff944e158fb647f524224150ececa2d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.2
|