A Java implementation of a behavior tree framework. This project supports encoding and decoding nodes from JSON, enabling flexible behavior tree configurations.
Behavior Trees (BTs) are hierarchical models used for decision-making in AI and other areas. In this implementation, nodes return one of three states: SUCCESS
, FAILURE
, or RUNNING
. To define and use nodes, implement the Node.java
interface.
There are three primary types of nodes to be aware of:
- IONode
- Decorator
- FlowController
IONode
is a specialized node that can declare inputs and outputs used in JSON configurations. Use the @Input
and @Output
annotations to define fields. In your JSON configuration, you can specify input
and output
objects that hold names and values of these variables.
A Decorator
node has one input and one output. It is used to modify the return value of another node. Currently, the implementation includes:
InverterDecorator.java
: Inverts the result of the child node.
A FlowController
node manages child nodes and determines the order of execution. There are three implementations:
SelectorFlow.java
SequenceFlow.java
SequenceFlowWithMemory.java
In JSON, you specify the children
array, which contains the nodes to be executed by the FlowController
.
Nodes can be decoded from JSON to create behavior trees. The JSON representation starts with a root node and includes definitions for child nodes as needed.
{
"children": [
{
"output": {
"outputValue": "{some_value}"
},
"type": "TestNode3"
},
{
"input": {
"someInput": "{some_value}",
"nickname": "wojtess"
},
"type": "TestNode4"
}
],
"input": {},
"output": {},
"type": "SequenceFlow"
}
-
Setup:
-
Build the Project:
- Use Maven to build the project:
mvn clean install
- Use Maven to build the project:
-
Define Nodes:
- Implement your custom nodes by extending
IONode
,Decorator
, orFlowController
.
- Implement your custom nodes by extending
-
Configure JSON:
- Create JSON files to define your behavior trees. Use the provided methods to decode and execute them.
For detailed usage and advanced configurations, please refer to the project's documentation and source code.