This is the final blog-post of the series (for previous parts see here and here). As promised, here we will see the implementation of Reinforcement Learning through Behavior Tree (in natural Unreal Engine environment). The method written is fairly general and can be used to generate BT corresponding to any RL based algorithm.
The k-armed bandit (which for our case turns into shooting colored boxes) algorithm can be categorized into 5 tasks.
- Select a box (based on probabilities and estimates)
- Rotate towards box (for more complex, locomotion may be involved)
- Shoot the box
- Wait (for reward assesement)
- Update the estimates
The tree built with this categorization of the tasks is shown in figure
The Engine also provides an powerful interface for Blueprints to interact with C++. This is a good way to unify the artistic and programming development of a game. We will show that in real time here.
Consider the task BTTask_FindAppBox node. The Blueprint implementation is shown in the figure
In the Engine, every BT task starts with the node Event Receive Execute AI. So we start with that and make the connection to Cast node yielding the object corresponding to class MAIPlayerController. Once that is done, we invoke the C++ method through the node Look for App Box and by setting the target pin as the casted object. The C++ method is posted here.
Similarly rest of the three tasks (except the Engine default task Wait) are implemented through this C++-Blueprint interface. Another example is BTTask_UpdateEstimates
with the corresponding C++ code posted here.