GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - s7jones/BrainTree: C++ behavior tree single header library

BranchesTags
Open more actions menu
 
 

Latest commit

 

History

40 Commits
40 Commits

Folders and files

NameName
Last commit message
Last commit date
build
build
 
 
src
src
 
 
BrainTree.h
BrainTree.h
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 

Repository files navigation

BrainTree

A C++ behavior tree header-only library.

Features

  • behavior tree
  • 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!", six times
#include <iostream>
#include <BrainTree.h>

class Action : public BrainTree::Node
{
public:
    Action() {}

    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 actionOne = std::make_shared<Action>();
    auto actionTwo = std::make_shared<Action>();
    auto actionThree = std::make_shared<Action>();
    sequence.addChild(actionOne);
    sequence.addChild(actionTwo);
    sequence.addChild(actionThree);
    tree.setRoot(sequence);
    tree.update();
}

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

int main()
{
    CreatingBehaviorTreeManually();

    CreatingBehaviorTreeUsingBuilders();

    return 0;
}

Composites

Selector

  • The Selector composite ticks each child node in order.
  • If a child succeeds or runs, the selector returns the same status.
  • In the next tick, it will try to run each child in order again.
  • If all children fails, only then does the selector fail.

Sequence

  • The Sequence composite ticks each child node in order.
  • If a child fails or runs, the sequence returns the same status.
  • In the next tick, it will try to run each child in order again.
  • If all children succeeds, only then does the sequence succeed.

StatefulSelector

  • The StatefulSelector composite ticks each child node in order, and remembers what child it prevously tried to tick.
  • If a child succeeds or runs, the stateful selector returns the same status.
  • In the next tick, it will try to run the next child or start from the beginning again.
  • If all children fails, only then does the stateful selector fail.

StatefulSequence

  • The StatefulSequence composite ticks each child node in order, and remembers what child it prevously tried to tick.
  • If a child fails or runs, the stateful sequence returns the same status.
  • In the next tick, it will try to run the next child or start from the beginning again.
  • If all children succeeds, only then does the stateful sequence succeed.

Builder

The Builder class makes it easier to create a behavior tree. You use three methods to build your tree: leaf<NodeType>(), composite<CompositeType>() and 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 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 (c) arvidsson

About

C++ behavior tree single header library

Resources

Readme
MIT license
Activity

Stars

3 stars

Watchers

1 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.