Blackboard is a very efficient tool utilized by AI agent for generating appropriate behavior. In this blog-post I shall demonstrate the Unreal Engine code, in action, using the BlackBoard class.
First we initialize the BlackBoard object in the following fashion with line 8
void AMAIController::SetGameRep(AMAIGameState *GR) { MAIGameRep = GR; // setup blackboard component if(!MAIGameRep->GetBlackBoard()) { UBlackboardComponent* BB = NewObject(this, TEXT("BlackboardComponent")); if(BB) { BB->RegisterComponent(); MAIGameRep->SetBlackBoard(BB); UBlackboardData* BlackboardAsset = NewObject(BB); BlackboardAsset->UpdatePersistentKey(FName("PlayerScore")); BB->InitializeBlackboard(*BlackboardAsset); } } }
Then, we register the component with line 11 and declare the UBlackBoardData with line 14. Next we add the key PlayerScore in the UBlackBoardData and finally initialize the BlackBoard with the asset. This is the code equivalent to the editor state shown below
The BlackBoard keys can be accessed by the code
GetGameRep()->GetBlackBoard()->GetValueAsFloat(FName("PlayerScore"));
The idea behind the BlackBoard is to provide a scratch work space with relevant data, required for the decision making purposes. Furthermore it is equipped with the ability to send notifications once data has been updated and cache the calculations saving redundant CPU processing time and power.
BlackBoard can be shared among several AI instances. It basically provides a common ground for all the AI instances to operate in collaborative manner. This gives rise to new collective behavior leading to more realistic gameplay and recreation.
Next, we want to focus our attention towards Reinforcement Learning algorithms which are more or less dormant in the game AI world (I really don’t have the clue why). But good news is that people are now gearing towards its implementation in game Engines (Unity seems first one to include that). For more information watch this video. There have been some white papers based on RL in game AI for instance Capture The Flag: the emergence of complex cooperative agents and Implementing Reinforcement Learning in Unreal Engine 4 with Blueprints.
Using the BlackBoard class, I applied Reinforcement Learning on Unreal Engine AI controller which is shown in the video below
The aim was to train the AI to shoot red boxes without actually coding it. This is called emergent behavior which was not included in the compiled code, but based on the rewards, AI learnt to shoot red boxes! More information on how I implemented RL will follow in the sequel blog-post. Stay tuned.