Skip to main content

A sample Python project

Project description

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 集成
  • 授权系统: 内置授权验证机制
  • 插件扩展: 支持通过插件系统扩展功能

快速开始

  1. 安装依赖:

    pip install -r requirements.txt
    
  2. 安装包:

    pip install .
    
  3. 设置授权码:

    from psbtree import set_sk_code
    set_sk_code("您的授权码")
    
  4. 运行示例:

    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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

psbtree-0.1.6-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.3 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

psbtree-0.1.6-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.4 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

psbtree-0.1.6-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.2 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

psbtree-0.1.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.9 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

psbtree-0.1.6-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.9 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

File details

Details for the file psbtree-0.1.6-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for psbtree-0.1.6-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cc68b057a66582a108a98c9bc8e1625747cb9c20e11d91c29354ad1587450683
MD5 99c06eed0dc8cb6aad4bbf8f3ddc1003
BLAKE2b-256 e366b67149751d9b2b257f156cccf8e32ba801153a08070bc2d1f4ee1212bdc3

See more details on using hashes here.

File details

Details for the file psbtree-0.1.6-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for psbtree-0.1.6-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ccd180afa76e5a860d99fbbf3605338300f2dd2b397844900a0ee80ee4691dbe
MD5 f3d00a87d9b26cf8902fdad01ea70ed3
BLAKE2b-256 9c37b659f7f2bdc8e8bb373281fd0f883aa62ba3e82e080be1be0d80fd774738

See more details on using hashes here.

File details

Details for the file psbtree-0.1.6-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for psbtree-0.1.6-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7e01854daf18962638743970635cbfecc5735e54fa02b253656b59851dc5b409
MD5 af6f419a95217aa930358c85a22ca163
BLAKE2b-256 a6d51ab8c1cd01a33a5b885833659391baaff771d15663d1df1e0a049caa6824

See more details on using hashes here.

File details

Details for the file psbtree-0.1.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for psbtree-0.1.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c1e7b6cb1714fd836ad7a26fc28b65d2c03ccea22bd854407d83d13660e7b4c1
MD5 edfbc3041c2d4c746e5af04c8b8d11c3
BLAKE2b-256 7aa0ad0ae70099d7ac88bb265296ee08fc7e83ded5a8853580b0a7a6da9f2a52

See more details on using hashes here.

File details

Details for the file psbtree-0.1.6-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for psbtree-0.1.6-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3d2af8efcf9ef6f6e7e9d298964767a2d6a5e3ca1a41fb654743774cf98f323d
MD5 407adc88c13e2fba2f1160bf38bc27c1
BLAKE2b-256 cb896c2089f55bb8577fa3d6469350d77391f88f10e0a8a9273765506f75e100

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page