The task given to us is to implement a behavior tree in two weeks for the GPR5204 module at SAE Institute Geneva. Here is how we’re planning to do it with the help of a documentation from the BTSK git repository : https://github.com/aigamedev/btsk
Behavior Tree classes and hierarchy
Overview
We have an enum called Status that represents the different statuses of the actions (Success, Running, Failure).
We have a base class called Behavior with three virtual functions that inheriting classes will implement :
OnInitialize() : Initializes status of action.
Update() : Updates status of action.
OnTerminate() : Is called when previous update is no longer running.
There is also a function to check the Status of the Behavior and react accordingly.
Then we have classes that inherit from the Behavior class :
Composite : class for nodes with multiple Behaviors to manage.
Decorator : class for nodes with only one Behavior.
Finally, we have two classes that inherit from the Composite class :
Selector : This class has conditional nodes, they’re only executed based on certain conditions/events.
Sequence : This class executes behaviors in order from left to right.
Variables
The Behavior class only has a Status as its main variable.
The Composite class has a vector of Behavior as variable.
The Decorator class has a Behavior as variable.
The Selector and Sequence classes both inherit the vector from the Composite class and have an iterator for said vector.
Why the difference between the function Update and the functions OnInitialize and OnTerminate? Why two with the On prefix?
Please be mindful that aigamedev/btsk is written in "old" C++, please be sure to write "modern" C++
I suppose the **Behavior* from the Decorator and the Composite class is a non-owning raw pointer (otherwise please use std::unique_ptr, which will make the tree self owning), if it's the case where are they going to be owned (if you say in a std::vector, they will** get invalidated so you might want to use indexes instead of non-owning raw pointer, which in both cases will require the creation of a super structure Tree which own all nodes from your behavior tree)
We will discuss optimizations and implementation scenario next week.
Behavior Tree
Introduction
The task given to us is to implement a behavior tree in two weeks for the GPR5204 module at SAE Institute Geneva. Here is how we’re planning to do it with the help of a documentation from the BTSK git repository : https://github.com/aigamedev/btsk
Behavior Tree classes and hierarchy
Overview
We have an enum called Status that represents the different statuses of the actions (Success, Running, Failure).
We have a base class called Behavior with three virtual functions that inheriting classes will implement :
OnInitialize() : Initializes status of action. Update() : Updates status of action. OnTerminate() : Is called when previous update is no longer running.
There is also a function to check the Status of the Behavior and react accordingly.
Then we have classes that inherit from the Behavior class :
Composite : class for nodes with multiple Behaviors to manage. Decorator : class for nodes with only one Behavior.
Finally, we have two classes that inherit from the Composite class :
Selector : This class has conditional nodes, they’re only executed based on certain conditions/events. Sequence : This class executes behaviors in order from left to right.
Variables
The Behavior class only has a Status as its main variable. The Composite class has a vector of Behavior as variable. The Decorator class has a Behavior as variable. The Selector and Sequence classes both inherit the vector from the Composite class and have an iterator for said vector.