Unreal Code Examples
void PlayerController::BeginPlay()
{
Super::BeginPlay();
World = NewObject<UARCWorld>(this);
ARCActionSpace = NewObject<UARCActionSpace>(this);
ARCStateSpace = NewObject<UARCStateSpace>(this);
Model = UARCBPLibrary::LoadModel(ModelConfig, false);
}
void PlayerController::Tick(float Delta)
{
Super::Tick(Delta);
// Create the world representation which we will convert to the state space matrix
World->InitializeWorld(
// All world attributes/objects that are relevant for the AI
);
// Get the state space for the model
TArray<double> State = ARCStateSpace->GetState(*World);
if (human)
{
// Convert the inputs into something the ARC agent can understand
TMap<FString, bool> Action = ARCActionSpace->ConvertInputToBools(*World);
// Add the observed state and action to the dataset
Model->Collect(State, Action);
} else {
// If ARC agent is controlling, then perform inference
auto ModelAction = UARCBPLibrary::SelectAction(Model,State);
// Execute the action in-game
auto Action = ARCActionSpace->ConvertActions(ModelAction);
}
}Last updated