behaviac
behaviac is a framework of the game AI development, and it also can be used as a rapid game prototype design tool. behaviac supports the behavior tree, finite state machine and hierarchical task network(BT, FSM, HTN)
Top Related Projects
Artificial Intelligence framework for games based on libGDX or not. Features: Steering Behaviors, Formation Motion, Pathfinding, Behavior Trees and Finite State Machines
Behavior Trees Library in C++. Batteries included.
Quick Overview
Behaviac is an open-source behavior tree library developed by Tencent. It provides a visual editor and runtime library for creating and executing behavior trees, which are commonly used in game AI and other decision-making systems. The library supports multiple programming languages and platforms, making it versatile for various projects.
Pros
- Visual editor for easy behavior tree creation and modification
- Supports multiple programming languages (C++, C#, Java) and platforms
- Extensive documentation and examples available
- Includes features like blackboards, decorators, and parallel nodes
Cons
- Learning curve for those unfamiliar with behavior trees
- Visual editor is Windows-only, limiting cross-platform development
- Some users report occasional stability issues with the editor
- Limited community support compared to some other AI frameworks
Code Examples
- Creating a simple behavior tree:
#include "behaviac/behaviac.h"
// Define a simple action
class SayHello : public behaviac::Action
{
BEHAVIAC_DECLARE_DYNAMIC_TYPE("SayHello", behaviac::Action);
virtual behaviac::EBTStatus execute(behaviac::Agent* pAgent)
{
printf("Hello, World!\n");
return behaviac::BT_SUCCESS;
}
};
// Create and run the behavior tree
behaviac::Workspace::GetInstance()->ExportMetas("../meta/");
behaviac::Workspace::GetInstance()->Load("../exported/SimpleBT");
behaviac::Agent* agent = behaviac::Agent::Create<behaviac::Agent>();
agent->btload("SimpleBT");
agent->btexec();
- Using a decorator:
// Define a decorator that limits execution count
class LimitDecorator : public behaviac::DecoratorNode
{
BEHAVIAC_DECLARE_DYNAMIC_TYPE("LimitDecorator", behaviac::DecoratorNode);
int m_limit;
int m_count;
public:
LimitDecorator() : m_limit(3), m_count(0) {}
virtual bool Evaluate(behaviac::Agent* pAgent)
{
return m_count < m_limit;
}
virtual behaviac::EBTStatus Update(behaviac::Agent* pAgent, behaviac::EBTStatus childStatus)
{
m_count++;
return childStatus;
}
};
- Using a blackboard:
// Set and get values from the blackboard
behaviac::Agent* agent = behaviac::Agent::Create<behaviac::Agent>();
agent->SetVariable("health", 100);
int health = agent->GetVariable<int>("health");
Getting Started
-
Clone the repository:
git clone https://github.com/Tencent/behaviac.git
-
Build the library and tools:
cd behaviac mkdir build && cd build cmake .. make
-
Include the library in your project:
#include "behaviac/behaviac.h"
-
Initialize behaviac in your main function:
behaviac::Workspace::GetInstance()->ExportMetas("../meta/"); behaviac::Workspace::GetInstance()->Load("../exported/YourBehaviorTree");
-
Create an agent and run the behavior tree:
behaviac::Agent* agent = behaviac::Agent::Create<behaviac::Agent>(); agent->btload("YourBehaviorTree"); agent->btexec();
Competitor Comparisons
Pros of PyBrain
- Written in Python, making it more accessible for data scientists and researchers
- Focuses on neural networks and reinforcement learning, offering specialized tools
- Includes a variety of pre-implemented algorithms and network architectures
Cons of PyBrain
- Less actively maintained, with fewer recent updates
- Limited documentation and community support compared to more modern libraries
- Primarily designed for research and experimentation, not production-ready systems
Code Comparison
PyBrain example (neural network creation):
from pybrain.tools.shortcuts import buildNetwork
from pybrain.structure import TanhLayer
net = buildNetwork(2, 3, 1, hiddenclass=TanhLayer)
behaviac example (behavior tree creation):
#include "behaviac/behaviac.h"
BehaviorTree* bt = BehaviorTree::CreateBehaviorTree("myBT");
bt->SetDomain("game");
While PyBrain focuses on neural networks and machine learning, behaviac is primarily used for behavior trees in game development and AI decision-making. PyBrain offers a higher-level abstraction for machine learning tasks, while behaviac provides more fine-grained control over AI behavior in real-time applications.
Artificial Intelligence framework for games based on libGDX or not. Features: Steering Behaviors, Formation Motion, Pathfinding, Behavior Trees and Finite State Machines
Pros of gdx-ai
- Integrated with the popular libGDX game development framework
- Supports a wider range of AI techniques, including pathfinding, steering behaviors, and state machines
- More active community and frequent updates
Cons of gdx-ai
- Less focused on behavior trees compared to behaviac
- May have a steeper learning curve for developers not familiar with libGDX
- Limited visual editing tools for AI design
Code Comparison
behaviac:
BEHAVIAC_BEGIN_PROPERTIES(CBTPlayer)
BEHAVIAC_REGISTER_PROPERTY("HP", "Health Points")
BEHAVIAC_REGISTER_METHOD(Move, "void Move()")
BEHAVIAC_END_PROPERTIES()
gdx-ai:
public class PlayerAgent extends Agent<Vector2> {
public PlayerAgent(Steerable<Vector2> owner) {
super(owner);
this.setSteeringBehavior(new Seek<Vector2>(this, target));
}
}
Both libraries offer ways to define agent behaviors, but behaviac focuses on behavior trees with a more declarative approach, while gdx-ai provides a broader set of AI tools with an object-oriented design.
Behavior Trees Library in C++. Batteries included.
Pros of BehaviorTree.CPP
- Lightweight and efficient C++ implementation
- Extensive documentation and examples
- Active community and regular updates
Cons of BehaviorTree.CPP
- Limited visual editing tools compared to behaviac
- Fewer built-in decorators and composites
- Steeper learning curve for beginners
Code Comparison
behaviac:
BEHAVIAC_BEGIN_PROPERTIES(CBTPlayer)
BEHAVIAC_REGISTER_PROPERTY("HP", "Health Points")
BEHAVIAC_REGISTER_METHOD(Move, "void Move()")
BEHAVIAC_END_PROPERTIES()
BehaviorTree.CPP:
static const char* xml_text = R"(
<root main_tree_to_execute="MainTree">
<BehaviorTree ID="MainTree">
<Sequence name="root_sequence">
<CheckBattery name="check_battery"/>
<OpenGripper name="open_gripper"/>
</Sequence>
</BehaviorTree>
</root>
)";
Both libraries offer powerful behavior tree implementations, but behaviac provides more extensive visual tools and a wider range of built-in nodes, while BehaviorTree.CPP focuses on a lightweight, efficient C++ implementation with better documentation and community support. The code examples showcase the different approaches to defining behavior trees, with behaviac using a property-based system and BehaviorTree.CPP utilizing XML for tree structure.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
访é®http://www.behaviac.com/è·åææ¡£ï¼æç¨ï¼APIï¼FAQï¼æºç ï¼ä¸è½½çä¸åç¸å ³èµæ
- behaviacæ¯æ¸¸æAIçå¼åæ¡æ¶ç»ä»¶ï¼ä¹æ¯æ¸¸æååçå¿«éè®¾è®¡å·¥å ·
- æ¯æè¡ä¸ºæ BTï¼ç¶ææºFSMï¼HTNçå¤ç§èå¼
- æ¹ä¾¿çç¼è¾ï¼å®æ¶å离线è°è¯
- æ¯æå ¨å¹³å°ï¼éç¨äºå®¢æ·ç«¯åæå¡å¨ï¼å©å游æå¿«éè¿ä»£å¼å
- å®æ¹ç½ç«æ¯ææ¡£ï¼æç¨ï¼APIï¼FAQï¼æºç ï¼ä¸è½½çä¸åçå ¥å£
- æ¨å¯ä»¥å å ¥æ们çQQ群433547396è·å¾å³æ¶ç帮å©æè ä¿¡æ¯åé¦ã
- BehaviacSetup*.exeæ¯å®è£ å ï¼å å«å¯æ§è¡çç¼è¾å¨å示ä¾ãå¦éè¦èªè¡æ建ï¼éè¦å»å®æ¹ç½ç«ægithub behaviacä¸è½½æå éæºç ï¼ç¶åå¯ä»¥è®¿é®buildè·åæ建帮å©
Visist http://www.behaviac.com/ for documents, tutorials, FAQs and all other information
-
behaviac is a framework of the game AI development, and it also can be used as a rapid game prototype design tool
-
behaviac supports the behavior tree, finite state machine and hierarchical task network
-
Behaviors can be designed and debugged in the designer, exported and executed by the game
-
The designer can only run on the Windows platforms, The run time library is implemented with C++ and C#, and it supports all major platforms (Windows, Linux, Android, iOS, Unity etc.) and Unity.
-
The C++ version is suitable for the client and server side.
-
Website for documents, tutorials, APIï¼FAQï¼source code, downloadsï¼etc.
-
BehaviacSetup*.exe is the setup package with the binary editor and demo executable. You can download/clone the source code from github behaviac
Top Related Projects
Artificial Intelligence framework for games based on libGDX or not. Features: Steering Behaviors, Formation Motion, Pathfinding, Behavior Trees and Finite State Machines
Behavior Trees Library in C++. Batteries included.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot