MIT License

项目介绍

arvidsson/BrainTree 是一个托管在 GitHub 上的开源项目,主要使用 C++ 编写,采用 MIT License 许可证,目前获得 246 个 Star、37 次 Fork。

仓库全名
arvidsson/BrainTree
开源许可证
MIT License
Star 数
246
Fork 数
37
未关闭 Issue
6

README 摘要

BrainTree A C++ behavior tree single header library. Features behavior tree implementation predefined composites predefined decorators (optional) rudimentary blackboard (optional) behavior tree builders Install Include BrainTree.h in your project. Example Composites Composite | Behaviour | Success | Running | Failure | Selector | Ticks each child node in order, starting from the beginning each tick | If a child…

完整内容见 GitHub 原始 README 或本页 。

常见问题

BrainTree 用什么语言开发?

主要使用 C++ 编写,采用 MIT License 许可证,目前有 246 个 Star。

BrainTree 可以免费商用吗?

仓库采用 MIT License 许可证,可免费使用与修改,商业使用请遵守许可证条款(例如保留版权声明与许可声明)。

如何获取 BrainTree 的源码?

可以直接克隆仓库:git clone https://github.com/arvidsson/BrainTree.git,默认分支为 master;安装与运行步骤见仓库 README。

BrainTree 最近还在维护吗?

仓库最近一次更新为 2023年9月22日,当前有 6 个未关闭 Issue;Star 数为 246,可作为社区活跃度的参考。

关于

C++ behavior tree single header library

描述取自 GitHub 官方 API,中文内容由 GitRead 中文社区 编辑团队整理。

简要分析

热度分
330
价值分
159
活跃状态
活跃

语言占比

C++

README

BrainTree

A C++ behavior tree single header library.

Features

  • behavior tree implementation
  • predefined composites
  • predefined decorators
  • (optional) rudimentary blackboard
  • (optional) behavior tree builders

Install

Include BrainTree.h in your project.

Example

// this example should print out "Hello, World!", four times
#include <iostream>
#include "BrainTree.h"

class Action : public BrainTree::Node
{
public:
    Status update() override
    {
        std::cout << "Hello, World!" << std::endl;
        return Node::Status::Success;
    }
};

void CreatingBehaviorTreeManually()
{
    BrainTree::BehaviorTree tree;
    auto sequence = std::make_shared<BrainTree::Sequence>();
    auto sayHello = std::make_shared<Action>();
    auto sayHelloAgain = std::make_shared<Action>();
    sequence->addChild(sayHello);
    sequence->addChild(sayHelloAgain);
    tree.setRoot(sequence);
    tree.update();
}

void CreatingBehaviorTreeUsingBuilders()
{
    auto tree = BrainTree::Builder()
        .composite<BrainTree::Sequence>()
            .leaf<Action>()
            .leaf<Action>()
        .end()
        .build();
    tree->update();
}

int main()
{
    CreatingBehaviorTreeManually();
    CreatingBehaviorTreeUsingBuilders();
    return 0;
}

Composites

Composite Behaviour Success Running Failure
Selector Ticks each child node in order, starting from the beginning each tick If a child succeeds If a child is running If all children fail
Sequence Ticks each child node in order, starting from the beginning each tick If all children succeed If a child is running If a child fails
StatefulSelector Ticks each child node in order, starting from the child ticked in previous tick If a child succeeds If a child is running If all children fail
StatefulSequence Ticks each child node in order, starting from the child ticked in previous tick If all children succeed If a child is running If a child fails

Decorators

Decorator Behaviour
Succeeder Always returns success
Failer Always returns failure
Inverter Inverts the result of the child node
Repeater Repeats until child node succeeds (infinitely or limited)
UntilSuccess Repeats until child node succeeds
UntilFailure Repeats until child node fails

Builder

The Builder class simplifies the process of creating a behavior tree. You use three methods to build your tree:

  • leaf<NodeType>()
  • composite<CompositeType>()
  • decorator<DecoratorType>()

Both composite() and decorator() require a corresponding call to end(), this marks where you are done adding children to a composite or a child to a decorator. At the very end you call build() which will then give you the finished behavior tree.

auto tree = Builder()
    .decorator<Repeater>()
        .composite<Sequence>()
            .leaf<SayHello>("Foo")
            .leaf<SayHello>("Bar")
        .end()
    .end()
    .build();

License

MIT © Pär Arvidsson 2015-2018

评论

暂无评论