From 48a625d40b04ce89f58ca073d35da30dde54f6b9 Mon Sep 17 00:00:00 2001 From: "K. R." Date: Thu, 11 Apr 2024 15:29:48 -0400 Subject: [PATCH] fixed logging --- ...gWormSimple.unity => TrainingSimple.unity} | 232 +----------------- ...e.unity.meta => TrainingSimple.unity.meta} | 0 Assets/Scripts/Agents/WormSimpleAgent.cs | 67 +++-- 3 files changed, 41 insertions(+), 258 deletions(-) rename Assets/Scenes/{TrainingWormSimple.unity => TrainingSimple.unity} (62%) rename Assets/Scenes/{TrainingWormSimple.unity.meta => TrainingSimple.unity.meta} (100%) diff --git a/Assets/Scenes/TrainingWormSimple.unity b/Assets/Scenes/TrainingSimple.unity similarity index 62% rename from Assets/Scenes/TrainingWormSimple.unity rename to Assets/Scenes/TrainingSimple.unity index 2459661..9d928f1 100644 --- a/Assets/Scenes/TrainingWormSimple.unity +++ b/Assets/Scenes/TrainingSimple.unity @@ -215,7 +215,7 @@ Camera: m_Enabled: 1 serializedVersion: 2 m_ClearFlags: 2 - m_BackGroundColor: {r: 0.46666667, g: 0.5647059, b: 0.60784316, a: 1} + m_BackGroundColor: {r: 0, g: 0, b: 0, a: 1} m_projectionMatrixMode: 1 m_GateFitMode: 2 m_FOVAxisMode: 0 @@ -271,126 +271,6 @@ Transform: m_Children: [] m_Father: {fileID: 0} m_LocalEulerAnglesHint: {x: 20.812, y: -90.00001, z: 0} ---- !u!1 &1537121771482511 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 4943719158343493} - - component: {fileID: 108227806465482735} - m_Layer: 0 - m_Name: Directional_Light - m_TagString: Untagged - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 4294967295 - m_IsActive: 1 ---- !u!4 &4943719158343493 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1537121771482511} - serializedVersion: 2 - m_LocalRotation: {x: 0.31598538, y: -0.3596048, z: 0.13088542, w: 0.8681629} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 1, y: 1, z: 1} - m_ConstrainProportionsScale: 0 - m_Children: [] - m_Father: {fileID: 0} - m_LocalEulerAnglesHint: {x: 40, y: -45, z: 0} ---- !u!108 &108227806465482735 -Light: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 1537121771482511} - m_Enabled: 1 - serializedVersion: 11 - m_Type: 1 - m_Color: {r: 1, g: 0.99570733, b: 0.984, a: 1} - m_Intensity: 0.7 - m_Range: 27.9 - m_SpotAngle: 74.8 - m_InnerSpotAngle: 57.579865 - m_CookieSize: 10 - m_Shadows: - m_Type: 2 - m_Resolution: -1 - m_CustomResolution: -1 - m_Strength: 0.8 - m_Bias: 0.05 - m_NormalBias: 0.4 - m_NearPlane: 0.2 - m_CullingMatrixOverride: - e00: 1 - e01: 0 - e02: 0 - e03: 0 - e10: 0 - e11: 1 - e12: 0 - e13: 0 - e20: 0 - e21: 0 - e22: 1 - e23: 0 - e30: 0 - e31: 0 - e32: 0 - e33: 1 - m_UseCullingMatrixOverride: 0 - m_Cookie: {fileID: 0} - m_DrawHalo: 0 - m_Flare: {fileID: 0} - m_RenderMode: 0 - m_CullingMask: - serializedVersion: 2 - m_Bits: 4294967295 - m_RenderingLayerMask: 1 - m_Lightmapping: 4 - m_LightShadowCasterMode: 0 - m_AreaSize: {x: 1, y: 1} - m_BounceIntensity: 1 - m_ColorTemperature: 6570 - m_UseColorTemperature: 0 - m_BoundingSphereOverride: {x: 0, y: 0, z: 0, w: 0} - m_UseBoundingSphereOverride: 0 - m_UseViewFrustumForShadowCasterCull: 1 - m_ShadowRadius: 0 - m_ShadowAngle: 0 ---- !u!54 &196764348222731229 -Rigidbody: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 7516032764376771973} - serializedVersion: 4 - m_Mass: 1000 - m_Drag: 0 - m_AngularDrag: 0.05 - m_CenterOfMass: {x: 0, y: 0, z: 0} - m_InertiaTensor: {x: 1, y: 1, z: 1} - m_InertiaRotation: {x: 0, y: 0, z: 0, w: 1} - m_IncludeLayers: - serializedVersion: 2 - m_Bits: 0 - m_ExcludeLayers: - serializedVersion: 2 - m_Bits: 0 - m_ImplicitCom: 1 - m_ImplicitTensor: 1 - m_UseGravity: 1 - m_IsKinematic: 1 - m_Interpolate: 0 - m_Constraints: 0 - m_CollisionDetection: 0 --- !u!1 &4363568567019248208 GameObject: m_ObjectHideFlags: 0 @@ -487,119 +367,9 @@ MonoBehaviour: maxStep: 0 hasUpgradedFromAgentParameters: 1 MaxStep: 10000 ---- !u!23 &7501056674170061351 -MeshRenderer: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 7516032764376771973} - m_Enabled: 1 - m_CastShadows: 1 - m_ReceiveShadows: 1 - m_DynamicOccludee: 1 - m_StaticShadowCaster: 0 - m_MotionVectors: 1 - m_LightProbeUsage: 1 - m_ReflectionProbeUsage: 1 - m_RayTracingMode: 2 - m_RayTraceProcedural: 0 - m_RayTracingAccelStructBuildFlagsOverride: 0 - m_RayTracingAccelStructBuildFlags: 1 - m_RenderingLayerMask: 1 - m_RendererPriority: 0 - m_Materials: - - {fileID: 2100000, guid: acba6bf2a290a496bb8989b42bf8698d, type: 2} - m_StaticBatchInfo: - firstSubMesh: 0 - subMeshCount: 0 - m_StaticBatchRoot: {fileID: 0} - m_ProbeAnchor: {fileID: 0} - m_LightProbeVolumeOverride: {fileID: 0} - m_ScaleInLightmap: 1 - m_ReceiveGI: 1 - m_PreserveUVs: 1 - m_IgnoreNormalsForChartDetection: 0 - m_ImportantGI: 0 - m_StitchLightmapSeams: 0 - m_SelectedEditorRenderState: 3 - m_MinimumChartSize: 4 - m_AutoUVMaxDistance: 0.5 - m_AutoUVMaxAngle: 89 - m_LightmapParameters: {fileID: 0} - m_SortingLayerID: 0 - m_SortingLayer: 0 - m_SortingOrder: 0 - m_AdditionalVertexStreams: {fileID: 0} ---- !u!33 &7508517068289125193 -MeshFilter: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 7516032764376771973} - m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0} ---- !u!1 &7516032764376771973 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 7519759559587844141} - - component: {fileID: 7508517068289125193} - - component: {fileID: 7539723310662674655} - - component: {fileID: 7501056674170061351} - - component: {fileID: 196764348222731229} - m_Layer: 14 - m_Name: Ground - m_TagString: ground - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 4294967295 - m_IsActive: 1 ---- !u!4 &7519759559587844141 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 7516032764376771973} - serializedVersion: 2 - m_LocalRotation: {x: -0, y: 0.7071068, z: -0, w: 0.7071068} - m_LocalPosition: {x: 0, y: 0, z: 0} - m_LocalScale: {x: 100.00003, y: 1, z: 100.00003} - m_ConstrainProportionsScale: 0 - m_Children: [] - m_Father: {fileID: 0} - m_LocalEulerAnglesHint: {x: 0, y: 90, z: 0} ---- !u!65 &7539723310662674655 -BoxCollider: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 7516032764376771973} - m_Material: {fileID: 0} - m_IncludeLayers: - serializedVersion: 2 - m_Bits: 0 - m_ExcludeLayers: - serializedVersion: 2 - m_Bits: 0 - m_LayerOverridePriority: 0 - m_IsTrigger: 0 - m_ProvidesContacts: 0 - m_Enabled: 1 - serializedVersion: 3 - m_Size: {x: 1, y: 1, z: 1} - m_Center: {x: 0, y: 0, z: 0} --- !u!1660057539 &9223372036854775807 SceneRoots: m_ObjectHideFlags: 0 m_Roots: - {fileID: 1392866532} - - {fileID: 4943719158343493} - - {fileID: 7519759559587844141} - {fileID: 4363568567019248209} diff --git a/Assets/Scenes/TrainingWormSimple.unity.meta b/Assets/Scenes/TrainingSimple.unity.meta similarity index 100% rename from Assets/Scenes/TrainingWormSimple.unity.meta rename to Assets/Scenes/TrainingSimple.unity.meta diff --git a/Assets/Scripts/Agents/WormSimpleAgent.cs b/Assets/Scripts/Agents/WormSimpleAgent.cs index b58a443..10c4511 100644 --- a/Assets/Scripts/Agents/WormSimpleAgent.cs +++ b/Assets/Scripts/Agents/WormSimpleAgent.cs @@ -1,41 +1,54 @@ +using CommandTerminal; using Unity.MLAgents; using Unity.MLAgents.Actuators; using Unity.MLAgents.Sensors; using UnityEngine; -public class WormSimpleAgent : Agent +namespace DialogosEngine { - public override void Initialize() + public class WormSimpleAgent : Agent { - // - } + CommandLogger Logger; + bool _IsInitialized = false; - public override void OnEpisodeBegin() - { - // - } + public override void Initialize() + { + Logger = new CommandLogger("WormSimpleAgent_log.txt", 1000); + Logger.Log($"[{StepCount}] Initialize"); + } - public override void CollectObservations(VectorSensor sensor) - { - sensor.AddObservation(Random.value); - } + public override void OnEpisodeBegin() + { + Logger.Log($"[{StepCount}] OnEpisodeBegin"); + _IsInitialized = true; + } - public void TouchedTarget() - { - AddReward(1f); - } + public override void CollectObservations(VectorSensor sensor) + { + var obs = Random.value; + sensor.AddObservation(obs); + Logger.Log($"[{StepCount}] CollectObservations: {obs}"); + } - public override void OnActionReceived(ActionBuffers actionBuffers) - { + public override void OnActionReceived(ActionBuffers actionBuffers) + { - var i = -1; - var continuousActions = actionBuffers.ContinuousActions; - var output = continuousActions[++i]; - Debug.Log(output); - } + var i = -1; + var continuousActions = actionBuffers.ContinuousActions; + var output = continuousActions[++i]; + Logger.Log($"[{StepCount}] OnActionReceived: {output}"); + } - void FixedUpdate() - { - AddReward(Random.value); + void FixedUpdate() + { + if(!_IsInitialized) + { + return; + } + + var reward = Random.value; + AddReward(reward); + Logger.Log($"[{StepCount}] FixedUpdate.reward: {reward}"); + } } -} +} \ No newline at end of file