// Copyright Epic Games, Inc. All Rights Reserved. #include "LearningAgentsGym.h" #include "LearningLog.h" #include "LearningAgentsEntityInterface.h" #include "LearningAgentsLearningComponentInterface.h" #include "Kismet/KismetMathLibrary.h" ALearningAgentsGymBase::ALearningAgentsGymBase() { PrimaryActorTick.bCanEverTick = false; PrimaryActorTick.bStartWithTickEnabled = false; } void ALearningAgentsGymBase::Initialize() { if (!RandomStream.IsValid()) { RandomStream = MakeShareable(new FRandomStream); RandomStream->Initialize(RandomSeed); } PopulateLearningComponents(); for (TScriptInterface& LearningComponent : LearningComponents) { LearningComponent->InitializeLearningComponent(); } OnGymInitialized.Broadcast(); } void ALearningAgentsGymBase::Reset() { OnBeginGymReset.Broadcast(); for (TScriptInterface& LearningComponent : LearningComponents) { LearningComponent->ResetLearningComponent(); } OnPostGymReset.Broadcast(); } void ALearningAgentsGymBase::GetRandomStream(FRandomStream& OutRandomStream) const { OutRandomStream = *RandomStream; } TSharedPtr ALearningAgentsGymBase::GetRandomStream() const { return RandomStream; } void ALearningAgentsGymBase::SetRandomStream(const TSharedPtr& InRandomStream) { RandomStream = InRandomStream; } bool ALearningAgentsGymBase::IsMemberOfGym(TObjectPtr Actor) const { if (Actor and Actor->Implements()) { return ILearningAgentsEntityInterface::Execute_GetGym(Actor) == this; } return false; } void ALearningAgentsGymBase::PopulateLearningComponents() { TArray> AllComponents; this->GetComponents(AllComponents); for (TObjectPtr Component : AllComponents) { if (Component && Component->Implements()) { TScriptInterface LearningComponentInterface = TScriptInterface(Component); LearningComponents.Add(LearningComponentInterface); } } }