V2.9 取消归一化,追加StateUI,改进代码

取消坐标归一化,朝向归一化算法改为transform.eulerAngles.y / 36f
This commit is contained in:
Koha9 2023-03-07 17:29:47 +09:00
parent faa4e7b065
commit 71f2687422
6 changed files with 30806 additions and 29634 deletions

View File

@ -1 +1 @@
{"count":1,"self":47.2882752,"total":50.6455875,"children":{"InitializeActuators":{"count":16,"self":0.0015004999999999999,"total":0.0015004999999999999,"children":null},"InitializeSensors":{"count":16,"self":0.0009998,"total":0.0009998,"children":null},"AgentSendState":{"count":2291,"self":0.0310393,"total":0.1206959,"children":{"CollectObservations":{"count":18328,"self":0.060121299999999996,"total":0.060121299999999996,"children":null},"WriteActionMask":{"count":18328,"self":0.0080016,"total":0.0080016,"children":null},"RequestDecision":{"count":18328,"self":0.0215337,"total":0.0215337,"children":null}}},"DecideAction":{"count":2291,"self":0.0295373,"total":0.0295373,"children":null},"AgentAct":{"count":2291,"self":3.2040772,"total":3.2040770999999997,"children":null}},"gauges":{"AKMAgent.CumulativeReward":{"count":9,"max":2563.29736,"min":-11622.02,"runningAverage":-9344.109,"value":2563.29736,"weightedAverage":-7458.709}},"metadata":{"timer_format_version":"0.1.0","start_time_seconds":"1676265049","unity_version":"2021.3.14f1","command_line_arguments":"C:\\Program Files\\Unity\\Hub\\Editor\\2021.3.14f1\\Editor\\Unity.exe -projectpath C:\\Users\\UCUNI\\OneDrive\\Unity\\ML-Agents\\Aimbot-ParallelEnv -useHub -hubIPC -cloudEnvironment production -licensingIpc LicenseClient-UCUNI -hubSessionId 09b1c250-aa7a-11ed-aae2-f5dbff6fb9ed -accessToken JZS3G7ukCMBqSLPYz0eBmgNgTUsctzdWLHiwknJRB1I00ef","communication_protocol_version":"1.5.0","com.unity.ml-agents_version":"2.0.1","scene_name":"InGame","end_time_seconds":"1676265100"}}
{"count":1,"self":103.6390464,"total":114.3152982,"children":{"InitializeActuators":{"count":16,"self":0.0024974999999999997,"total":0.0024974999999999997,"children":null},"InitializeSensors":{"count":16,"self":0.0020104999999999997,"total":0.0020104999999999997,"children":null},"AgentSendState":{"count":5455,"self":0.0948132,"total":0.9806398,"children":{"CollectObservations":{"count":43640,"self":0.82321499999999992,"total":0.82321499999999992,"children":null},"WriteActionMask":{"count":43640,"self":0.013517999999999999,"total":0.013517999999999999,"children":null},"RequestDecision":{"count":43640,"self":0.0490936,"total":0.0490936,"children":null}}},"DecideAction":{"count":5455,"self":0.099675699999999992,"total":0.099675699999999992,"children":null},"AgentAct":{"count":5455,"self":9.5909199999999988,"total":9.5909201,"children":null}},"gauges":{"AKMAgent.CumulativeReward":{"count":26,"max":6761.257,"min":-5718.909,"runningAverage":-2722.07129,"value":6761.257,"weightedAverage":878.3678}},"metadata":{"timer_format_version":"0.1.0","start_time_seconds":"1677964013","unity_version":"2021.3.14f1","command_line_arguments":"C:\\Program Files\\Unity\\Hub\\Editor\\2021.3.14f1\\Editor\\Unity.exe -projectpath C:\\Users\\UCUNI\\OneDrive\\Unity\\ML-Agents\\Aimbot-ParallelEnv -useHub -hubIPC -cloudEnvironment production -licensingIpc LicenseClient-UCUNI -hubSessionId d67c88a0-ba02-11ed-a3ce-33b55950a3a4 -accessToken WdVReGPmmCLBbN81ypuBAiDvpIGsP4S76e58UuC3fpo00ef","communication_protocol_version":"1.5.0","com.unity.ml-agents_version":"2.0.1","scene_name":"InGame","end_time_seconds":"1677964127"}}

File diff suppressed because it is too large Load Diff

View File

@ -73,6 +73,15 @@ public class AgentWithGun : Agent
private TargetController targetCon;
private HUDController hudController;
// observation
float[] myObserve = new float[4];
float[] rayTagResult;
float[] rayTagResultOnehot;
float[] rayDisResult;
float[] targetStates;
float remainTime;
float inAreaState;
[System.NonSerialized] public int finishedState;
private void Start()
@ -438,19 +447,26 @@ public override void CollectObservations(VectorSensor sensor)
{
//List<float> enemyLDisList = RaySensors.enemyLDisList;// All Enemy Lside Distances
//List<float> enemyRDisList = RaySensors.enemyRDisList;// All Enemy Rside Distances
float[] myObserve = { transform.localPosition.x/raySensors.viewDistance, transform.localPosition.y / raySensors.viewDistance, transform.localPosition.z / raySensors.viewDistance, transform.eulerAngles.y/360f };
float[] rayTagResult = raySensors.rayTagResult;// 探测用RayTag结果 float[](raySensorNum,1)
float[] rayTagResultOnehot = raySensors.rayTagResultOneHot.ToArray(); // 探测用RayTagonehot结果 List<int>[](raySensorNum*Tags,1)
float[] rayDisResult = raySensors.rayDisResult; // 探测用RayDis结果 float[](raySensorNum,1)
float[] targetStates = targetCon.targetState; // (6) targettype, target x,y,z, firebasesAreaDiameter
float remainTime = targetCon.leftTime;
/**myObserve[0] = transform.localPosition.x / raySensors.viewDistance;
myObserve[1] = transform.localPosition.y / raySensors.viewDistance;
myObserve[2] = transform.localPosition.z / raySensors.viewDistance;
myObserve[3] = transform.eulerAngles.y / 360f;**/
myObserve[0] = transform.localPosition.x;
myObserve[1] = transform.localPosition.y;
myObserve[2] = transform.localPosition.z;
myObserve[3] = transform.eulerAngles.y / 36f;
rayTagResult = raySensors.rayTagResult;// 探测用RayTag结果 float[](raySensorNum,1)
rayTagResultOnehot = raySensors.rayTagResultOneHot.ToArray(); // 探测用RayTagonehot结果 List<int>[](raySensorNum*Tags,1)
rayDisResult = raySensors.rayDisResult; // 探测用RayDis结果 float[](raySensorNum,1)
targetStates = targetCon.targetState; // (6) targettype, target x,y,z, firebasesAreaDiameter
remainTime = targetCon.leftTime;
inAreaState = targetCon.getInAreaState();
gunReadyToggle = gunReady();
//float[] focusEnemyObserve = RaySensors.focusEnemyInfo;// 最近的Enemy情报 float[](3,1) MinEnemyIndex,x,z
//sensor.AddObservation(allEnemyNum); // 敌人数量 int
sensor.AddObservation(targetStates);// (6) targettype, target x,y,z, firebasesAreaDiameter
sensor.AddObservation(targetCon.getInAreaState()); // (1)
sensor.AddObservation(inAreaState); // (1)
sensor.AddObservation(remainTime); // (1)
sensor.AddObservation(gunReadyToggle); //(1) save gun is ready?
sensor.AddObservation(myObserve); // (4)自机位置xyz+朝向 float[](4,1)
@ -463,6 +479,7 @@ public override void CollectObservations(VectorSensor sensor)
sensor.AddObservation(rayTagResult);
}
sensor.AddObservation(rayDisResult); // 探测用RayDis结果 float[](raySensorNum,1)
EnvUICon.updateStateText(targetStates, inAreaState, remainTime, gunReadyToggle, myObserve, rayTagResultOnehot, rayDisResult);
/*foreach(float aaa in rayDisResult)
{
Debug.Log(aaa);

View File

@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
@ -16,9 +17,11 @@ public class EnvironmentUIControl : MonoBehaviour
public TextMeshProUGUI remainTimeText;
public TextMeshProUGUI targetTypeText;
public TextMeshProUGUI winLoseText;
public TextMeshProUGUI stateText;
public float resultTimeout = 1f;
public GameObject gaugeImgObj;
private StringBuilder stateBuilder = new StringBuilder();
private LineChart realTimeRewardChart = null;
private TargetController targetController;
private ParameterContainer paramContainer;
@ -153,4 +156,39 @@ public void updateTargetType(int targetInt)
break;
}
}
// update state text
// public TextMeshProUGUI stateText;
// targetState[0] = targetTypeInt;
// targetState[1] = targetPosition.x / raySensors.viewDistance; // normalization
// targetState[2] = targetPosition.y / raySensors.viewDistance;
// targetState[3] = targetPosition.z / raySensors.viewDistance;
// targetState[4] = blockCont.thisBlock.firebasesAreaDiameter / raySensors.viewDistance;
// targetState[5] = blockCont.thisBlock.belongRatio;
// float[] myObserve = { transform.localPosition.x/raySensors.viewDistance, transform.localPosition.y / raySensors.viewDistance, transform.localPosition.z / raySensors.viewDistance, transform.eulerAngles.y/360f }
// ??????????string??"targetType: 1.0 \r\n targetX: 2.0 \r\n"
public void updateStateText(float[] targetStates,float inAreaState,float remainTime, bool gunReadyToggle, float[] myObserve, float[] rayTagResultOnehot, float[] rayDisResult)
{
stateBuilder.Clear();
stateBuilder.Append($"States:\r\nTType:{targetStates[0]}");
stateBuilder.Append("\r\nTPosition:");
stateBuilder.Append(targetStates[1]).Append(targetStates[2]).Append(targetStates[3]);
stateBuilder.Append("\r\nTDiameter:");
stateBuilder.Append(targetStates[4]);
stateBuilder.Append("\r\nTRatio:");
stateBuilder.Append(targetStates[5]);
stateBuilder.Append("\r\nInArea:");
stateBuilder.Append(inAreaState);
stateBuilder.Append("\r\nRemainTime:");
stateBuilder.Append(remainTime);
stateBuilder.Append("\r\nGunReady:");
stateBuilder.Append(gunReadyToggle);
stateBuilder.Append("\r\nMyPosition:");
stateBuilder.Append(myObserve[0]).Append(myObserve[1]).Append(myObserve[2]);
stateBuilder.Append("\r\nMyRotation:");
stateBuilder.Append(myObserve[3]);
stateText.text = stateBuilder.ToString();
}
}

View File

@ -209,9 +209,12 @@ public void updateTargetStates()
else
{
targetState[0] = targetTypeInt;
targetState[1] = targetPosition.x / raySensors.viewDistance; // normalization
/* targetState[1] = targetPosition.x / raySensors.viewDistance; // normalization
targetState[2] = targetPosition.y / raySensors.viewDistance;
targetState[3] = targetPosition.z / raySensors.viewDistance;
targetState[3] = targetPosition.z / raySensors.viewDistance;*/
targetState[1] = targetPosition.x; // normalization
targetState[2] = targetPosition.y;
targetState[3] = targetPosition.z;
targetState[4] = blockCont.thisBlock.firebasesAreaDiameter / raySensors.viewDistance;
targetState[5] = blockCont.thisBlock.belongRatio;
}
@ -396,6 +399,8 @@ public float getDistanceReward(float nowDistance,int inarea)
}
else
{
// out of area
// thisSceneReward = paramCon.distanceReward * Math.Clamp(lastDistance - nowDistance, 0, 100);
thisSceneReward = paramCon.distanceReward * (lastDistance - nowDistance);
}
lastDistance = nowDistance;

View File

@ -14,10 +14,10 @@ MonoBehaviour:
m_EditorClassIdentifier:
m_PixelRect:
serializedVersion: 2
x: -152
y: 101
width: 1858
height: 1037
x: -130
y: 190
width: 1852
height: 989
m_ShowMode: 4
m_Title: Hierarchy
m_RootView: {fileID: 12}
@ -97,7 +97,7 @@ MonoBehaviour:
m_MinSize: {x: 100, y: 121}
m_MaxSize: {x: 4000, y: 4021}
vertical: 0
controlID: 48
controlID: 149
--- !u!114 &5
MonoBehaviour:
m_ObjectHideFlags: 52
@ -114,9 +114,9 @@ MonoBehaviour:
m_Position:
serializedVersion: 2
x: 0
y: 714
width: 1083
height: 273
y: 680
width: 1077
height: 259
m_MinSize: {x: 231, y: 271}
m_MaxSize: {x: 10001, y: 10021}
m_ActualView: {fileID: 18}
@ -144,12 +144,12 @@ MonoBehaviour:
serializedVersion: 2
x: 0
y: 0
width: 1083
height: 987
width: 1077
height: 939
m_MinSize: {x: 100, y: 200}
m_MaxSize: {x: 8096, y: 16192}
vertical: 1
controlID: 80
controlID: 19
--- !u!114 &7
MonoBehaviour:
m_ObjectHideFlags: 52
@ -166,11 +166,11 @@ MonoBehaviour:
m_Position:
serializedVersion: 2
x: 0
y: 714
width: 335
height: 273
m_MinSize: {x: 102, y: 121}
m_MaxSize: {x: 4002, y: 4021}
y: 464
width: 332
height: 475
m_MinSize: {x: 100, y: 100}
m_MaxSize: {x: 4000, y: 4000}
m_ActualView: {fileID: 22}
m_Panes:
- {fileID: 22}
@ -193,14 +193,14 @@ MonoBehaviour:
- {fileID: 7}
m_Position:
serializedVersion: 2
x: 1083
x: 1077
y: 0
width: 335
height: 987
width: 332
height: 939
m_MinSize: {x: 100, y: 200}
m_MaxSize: {x: 8096, y: 16192}
vertical: 1
controlID: 141
controlID: 69
--- !u!114 &9
MonoBehaviour:
m_ObjectHideFlags: 52
@ -218,10 +218,10 @@ MonoBehaviour:
serializedVersion: 2
x: 0
y: 0
width: 335
height: 714
m_MinSize: {x: 202, y: 221}
m_MaxSize: {x: 4002, y: 4021}
width: 332
height: 464
m_MinSize: {x: 200, y: 200}
m_MaxSize: {x: 4000, y: 4000}
m_ActualView: {fileID: 20}
m_Panes:
- {fileID: 20}
@ -247,12 +247,12 @@ MonoBehaviour:
serializedVersion: 2
x: 0
y: 30
width: 1858
height: 987
width: 1852
height: 939
m_MinSize: {x: 300, y: 200}
m_MaxSize: {x: 24288, y: 16192}
vertical: 0
controlID: 79
controlID: 68
--- !u!114 &11
MonoBehaviour:
m_ObjectHideFlags: 52
@ -268,12 +268,12 @@ MonoBehaviour:
m_Children: []
m_Position:
serializedVersion: 2
x: 1418
x: 1409
y: 0
width: 440
height: 987
m_MinSize: {x: 276, y: 71}
m_MaxSize: {x: 4001, y: 4021}
width: 443
height: 939
m_MinSize: {x: 275, y: 50}
m_MaxSize: {x: 4000, y: 4000}
m_ActualView: {fileID: 19}
m_Panes:
- {fileID: 19}
@ -299,8 +299,8 @@ MonoBehaviour:
serializedVersion: 2
x: 0
y: 0
width: 1858
height: 1037
width: 1852
height: 989
m_MinSize: {x: 875, y: 300}
m_MaxSize: {x: 10000, y: 10000}
m_UseTopView: 1
@ -324,7 +324,7 @@ MonoBehaviour:
serializedVersion: 2
x: 0
y: 0
width: 1858
width: 1852
height: 30
m_MinSize: {x: 0, y: 0}
m_MaxSize: {x: 0, y: 0}
@ -345,8 +345,8 @@ MonoBehaviour:
m_Position:
serializedVersion: 2
x: 0
y: 1017
width: 1858
y: 969
width: 1852
height: 20
m_MinSize: {x: 0, y: 0}
m_MaxSize: {x: 0, y: 0}
@ -367,10 +367,10 @@ MonoBehaviour:
serializedVersion: 2
x: 0
y: 0
width: 1083
height: 714
m_MinSize: {x: 201, y: 221}
m_MaxSize: {x: 4001, y: 4021}
width: 1077
height: 680
m_MinSize: {x: 200, y: 200}
m_MaxSize: {x: 4000, y: 4000}
m_ActualView: {fileID: 21}
m_Panes:
- {fileID: 21}
@ -516,10 +516,10 @@ MonoBehaviour:
m_Tooltip:
m_Pos:
serializedVersion: 2
x: -152
y: 845
width: 1082
height: 252
x: -130
y: 900
width: 1076
height: 238
m_ViewDataDictionary: {fileID: 0}
m_OverlayCanvas:
m_LastAppliedPresetName: Default
@ -549,10 +549,10 @@ MonoBehaviour:
m_LockTracker:
m_IsLocked: 0
m_FolderTreeState:
scrollPos: {x: 0, y: 104}
m_SelectedIDs: ea780000
m_LastClickedID: 30954
m_ExpandedIDs: 00000000a0780000a2780000a4780000a6780000a8780000e478000000ca9a3b
scrollPos: {x: 0, y: 172}
m_SelectedIDs: 22790000
m_LastClickedID: 31010
m_ExpandedIDs: 00000000e0780000e2780000e4780000e6780000e87800001c79000000ca9a3b
m_RenameOverlay:
m_UserAcceptedRename: 0
m_Name:
@ -580,7 +580,7 @@ MonoBehaviour:
scrollPos: {x: 0, y: 0}
m_SelectedIDs:
m_LastClickedID: 0
m_ExpandedIDs: 00000000a0780000a2780000a4780000a6780000a8780000
m_ExpandedIDs: 00000000e0780000e2780000e4780000e6780000e8780000
m_RenameOverlay:
m_UserAcceptedRename: 0
m_Name:
@ -632,7 +632,7 @@ MonoBehaviour:
m_Icon: {fileID: 0}
m_ResourceFile:
m_NewAssetIndexInList: -1
m_ScrollPosition: {x: 0, y: 83}
m_ScrollPosition: {x: 0, y: 84}
m_GridSize: 16
m_SkipHiddenPackages: 0
m_DirectoriesAreaWidth: 355
@ -656,10 +656,10 @@ MonoBehaviour:
m_Tooltip:
m_Pos:
serializedVersion: 2
x: 1419
y: 19
width: 439
height: 966
x: 1279
y: 220
width: 442
height: 918
m_ViewDataDictionary: {fileID: 0}
m_OverlayCanvas:
m_LastAppliedPresetName: Default
@ -697,10 +697,10 @@ MonoBehaviour:
m_Tooltip:
m_Pos:
serializedVersion: 2
x: 1
y: 19
width: 333
height: 693
x: 947
y: 220
width: 330
height: 443
m_ViewDataDictionary: {fileID: 0}
m_OverlayCanvas:
m_LastAppliedPresetName: Default
@ -710,7 +710,7 @@ MonoBehaviour:
scrollPos: {x: 0, y: 0}
m_SelectedIDs:
m_LastClickedID: 0
m_ExpandedIDs: 32fbffffc06a0000
m_ExpandedIDs: fc99ffff589affffec9bffff32fbffff886a0000
m_RenameOverlay:
m_UserAcceptedRename: 0
m_Name:
@ -754,10 +754,10 @@ MonoBehaviour:
m_Tooltip:
m_Pos:
serializedVersion: 2
x: 0
y: 19
width: 1082
height: 693
x: -130
y: 220
width: 1076
height: 659
m_ViewDataDictionary: {fileID: 0}
m_OverlayCanvas:
m_LastAppliedPresetName: Default
@ -992,9 +992,9 @@ MonoBehaviour:
m_PlayAudio: 0
m_AudioPlay: 0
m_Position:
m_Target: {x: -187.27528, y: -575.05884, z: 130.28072}
m_Target: {x: -193.44568, y: -432.5919, z: 284.7471}
speed: 2
m_Value: {x: -187.27528, y: -575.05884, z: 130.28072}
m_Value: {x: -193.44568, y: -432.5919, z: 284.7471}
m_RenderMode: 0
m_CameraMode:
drawMode: 0
@ -1041,13 +1041,13 @@ MonoBehaviour:
m_GridAxis: 1
m_gridOpacity: 0.5
m_Rotation:
m_Target: {x: 0.5423778, y: 0.009795776, z: -0.0063570384, w: 0.8400479}
m_Target: {x: 0.40636468, y: 0.03531183, z: -0.015755024, w: 0.9128847}
speed: 2
m_Value: {x: 0.5423804, y: 0.009795822, z: -0.006357068, w: 0.84005183}
m_Value: {x: 0.40636754, y: 0.03531208, z: -0.015755134, w: 0.91289115}
m_Size:
m_Target: 355.98242
m_Target: 336.21252
speed: 2
m_Value: 355.98242
m_Value: 321.73447
m_Ortho:
m_Target: 0
speed: 2
@ -1092,10 +1092,10 @@ MonoBehaviour:
m_Tooltip:
m_Pos:
serializedVersion: 2
x: 1
y: 733
width: 333
height: 252
x: 947
y: 684
width: 330
height: 454
m_ViewDataDictionary: {fileID: 0}
m_OverlayCanvas:
m_LastAppliedPresetName: Default