V2.7 Normalized state

Normalized distance and rotation state.
This commit is contained in:
Koha9 2022-12-18 20:17:08 +09:00
parent 64ada808de
commit 5ccb06c545
5 changed files with 30402 additions and 30395 deletions

View File

@ -1 +1 @@
{"count":1,"self":15.2624832,"total":16.0374865,"children":{"InitializeActuators":{"count":16,"self":0.0020017999999999998,"total":0.0020017999999999998,"children":null},"InitializeSensors":{"count":16,"self":0.0020989999999999997,"total":0.0020989999999999997,"children":null},"AgentSendState":{"count":547,"self":0.0070130999999999995,"total":0.034057899999999995,"children":{"CollectObservations":{"count":4376,"self":0.0200301,"total":0.0200301,"children":null},"WriteActionMask":{"count":4376,"self":0.0015003,"total":0.0015003,"children":null},"RequestDecision":{"count":4376,"self":0.0055144,"total":0.0055144,"children":null}}},"DecideAction":{"count":547,"self":0.0085414999999999987,"total":0.0085414999999999987,"children":null},"AgentAct":{"count":547,"self":0.72779699999999992,"total":0.72779699999999992,"children":null}},"gauges":{},"metadata":{"timer_format_version":"0.1.0","start_time_seconds":"1670633960","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-BIduOqLJT8GiF8SNWhGj_ -hubSessionId e2ebfc30-77ac-11ed-bf56-45d250d830d4 -accessToken aCi_2ERt33bo42jVTu8X3P-PvUkABd5hiU-fyHtjEnA00ef","communication_protocol_version":"1.5.0","com.unity.ml-agents_version":"2.0.1","scene_name":"InGame","end_time_seconds":"1670633976"}}
{"count":1,"self":13.315304,"total":13.988529499999999,"children":{"InitializeActuators":{"count":16,"self":0.0014992,"total":0.0014992,"children":null},"InitializeSensors":{"count":16,"self":0.0010057,"total":0.0010057,"children":null},"AgentSendState":{"count":463,"self":0.0070088,"total":0.025683599999999997,"children":{"CollectObservations":{"count":3704,"self":0.0136738,"total":0.0136738,"children":null},"WriteActionMask":{"count":3704,"self":0.0010000999999999999,"total":0.0010000999999999999,"children":null},"RequestDecision":{"count":3704,"self":0.0040009,"total":0.0040009,"children":null}}},"DecideAction":{"count":463,"self":0.0090286,"total":0.0090286,"children":null},"AgentAct":{"count":463,"self":0.63550869999999993,"total":0.63550869999999993,"children":null}},"gauges":{},"metadata":{"timer_format_version":"0.1.0","start_time_seconds":"1670806723","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-YRG3pCS8ZgFNZRYWWEQNT -hubSessionId bd156e60-79a0-11ed-822f-5975ccdc385f -accessToken Oh87gx5N8gBlKDUL5eNZyAhhMBi2H5U90gq84xokOa800ef","communication_protocol_version":"1.5.0","com.unity.ml-agents_version":"2.0.1","scene_name":"InGame","end_time_seconds":"1670806737"}}

File diff suppressed because it is too large Load Diff

View File

@ -63,7 +63,7 @@ public class AgentWithGun : Agent
private string myTag = "";
private float lastEnemyFacingDistance = 0f; // record last enemy facing minimum distance
// scripts
private RaySensors rayScript;
private RaySensors raySensors;
private CharacterController PlayerController;
private EnvironmentUIControl EnvUICon;
private ParameterContainer paramContainer;
@ -82,7 +82,7 @@ private void Start()
EnvUICon = EnvironmentUIControlObj.GetComponent<EnvironmentUIControl>();
targetCon = TargetControllerObj.GetComponent<TargetController>();
hudController = HUDObj.GetComponent<HUDController>();
rayScript = GetComponent<RaySensors>();
raySensors = GetComponent<RaySensors>();
PlayerController = this.transform.GetComponent<CharacterController>();
// Environment parameters
lockMouse = paramContainer.lockMouse;
@ -263,7 +263,7 @@ float ballistic()
{
// while if attack mode
float targetDis = Vector3.Distance(blockContainer.thisBlock.transform.position, transform.position);
if (targetDis <= rayScript.viewDistance)
if (targetDis <= raySensors.viewDistance)
{
// Debug.DrawRay(new Vector3(0,0,0), viewPoint, Color.red);
if (Vector3.Distance(ray.origin + (ray.direction * targetDis), blockContainer.thisBlock.transform.position) <= blockContainer.thisBlock.firebasesAreaDiameter / 2)
@ -310,10 +310,10 @@ float facingReward()
isFacingtoEnemy = true;
}
}
if (rayScript.inViewEnemies.Count > 0 && !isFacingtoEnemy) {
if (raySensors.inViewEnemies.Count > 0 && !isFacingtoEnemy) {
// have enemy in view
List<float> projectionDis = new List<float>();
foreach (GameObject thisEnemy in rayScript.inViewEnemies)
foreach (GameObject thisEnemy in raySensors.inViewEnemies)
{
// for each enemy in view
Vector3 projection = Vector3.Project(thisEnemy.transform.position - transform.position, (ray.direction * 10));
@ -346,7 +346,7 @@ float facingReward()
{
// attack mode
float targetDis = Vector3.Distance(blockContainer.thisBlock.transform.position, transform.position);
if(targetDis <= rayScript.viewDistance)
if(targetDis <= raySensors.viewDistance)
{
// Debug.DrawRay(new Vector3(0,0,0), viewPoint, Color.red);
if (Vector3.Distance(ray.origin + (ray.direction * targetDis), blockContainer.thisBlock.transform.position) <= blockContainer.thisBlock.firebasesAreaDiameter / 2)
@ -419,7 +419,7 @@ public override void OnEpisodeBegin()
{
EnvUICon.initChart();
}
rayScript.updateRayInfo(); // update raycast
raySensors.updateRayInfo(); // update raycast
}
// ML-AGENTS处理-------------------------------------------------------------------------------------------ML-AGENTS
// 观察情报
@ -428,10 +428,10 @@ 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, transform.localPosition.y, transform.localPosition.z, transform.eulerAngles.y/360f };
float[] rayTagResult = rayScript.rayTagResult;// 探测用RayTag结果 float[](raySensorNum,1)
float[] rayTagResultOnehot = rayScript.rayTagResultOneHot.ToArray(); // 探测用RayTagonehot结果 List<int>[](raySensorNum*Tags,1)
float[] rayDisResult = rayScript.rayDisResult; // 探测用RayDis结果 float[](raySensorNum,1)
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;
gunReadyToggle = gunReady();
@ -452,6 +452,11 @@ public override void CollectObservations(VectorSensor sensor)
sensor.AddObservation(rayTagResult);
}
sensor.AddObservation(rayDisResult); // 探测用RayDis结果 float[](raySensorNum,1)
/*foreach(float aaa in rayDisResult)
{
Debug.Log(aaa);
}
Debug.LogWarning("------------");*/
//sensor.AddObservation(focusEnemyObserve); // 最近的Enemy情报 float[](3,1) MinEnemyIndex,x,z
//sensor.AddObservation(raySensorNum); // raySensor数量 int
//sensor.AddObservation(remainTime); // RemainTime int
@ -473,7 +478,7 @@ public override void OnActionReceived(ActionBuffers actionBuffers)
shoot = mouseShoot;
cameraControl(Mouse_X, 0);
moveAgent(vertical, horizontal);
rayScript.updateRayInfo(); // update raycast
raySensors.updateRayInfo(); // update raycast
//判断结束
float sceneReward = 0f;

View File

@ -63,6 +63,7 @@ public enum EndType { Win, Lose, Running, Num };
private CharacterController agentCharaCon;
private WorldUIController worldUICon;
private HUDController hudCon;
private RaySensors raySensors;
// Start is called before the first frame update
void Start()
@ -84,6 +85,7 @@ void Start()
paramCon = ParameterContainerObj.GetComponent<ParameterContainer>();
worldUICon = WorldUIObj.GetComponent<WorldUIController>();
hudCon = HUDObj.GetComponent<HUDController>();
raySensors = AgentObj.GetComponent<RaySensors>();
freeProb = 1 - attackProb - gotoProb - defenceProb;
targetNum = (int)Targets.Num;
if (freeProb < 0)
@ -183,7 +185,7 @@ public void rollNewScene()
}
else
{
Debug.Log("Free");
//Debug.Log("Free");
targetTypeInt = (int)Targets.Free;
enemyCont.destroyAllEnemys();
enemyCont.randomInitEnemys(hudCon.enemyNum);
@ -207,10 +209,10 @@ public void updateTargetStates()
else
{
targetState[0] = targetTypeInt;
targetState[1] = targetPosition.x;
targetState[2] = targetPosition.y;
targetState[3] = targetPosition.z;
targetState[4] = blockCont.thisBlock.firebasesAreaDiameter;
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;
}
}

View File

@ -15,9 +15,9 @@ MonoBehaviour:
m_PixelRect:
serializedVersion: 2
x: -1073
y: -689
y: -653
width: 1080
height: 631
height: 595
m_ShowMode: 0
m_Title: Game
m_RootView: {fileID: 4}
@ -38,12 +38,12 @@ MonoBehaviour:
m_EditorClassIdentifier:
m_PixelRect:
serializedVersion: 2
x: -33
y: 148
x: 70
y: 53
width: 1840
height: 1019
m_ShowMode: 4
m_Title: Scene
m_Title: Inspector
m_RootView: {fileID: 12}
m_MinSize: {x: 875, y: 542}
m_MaxSize: {x: 10000, y: 10000}
@ -66,7 +66,7 @@ MonoBehaviour:
x: 0
y: 0
width: 1080
height: 631
height: 595
m_MinSize: {x: 100, y: 121}
m_MaxSize: {x: 4000, y: 4021}
m_ActualView: {fileID: 16}
@ -93,11 +93,11 @@ MonoBehaviour:
x: 0
y: 0
width: 1080
height: 631
height: 595
m_MinSize: {x: 100, y: 121}
m_MaxSize: {x: 4000, y: 4021}
vertical: 0
controlID: 57
controlID: 152
--- !u!114 &5
MonoBehaviour:
m_ObjectHideFlags: 52
@ -149,7 +149,7 @@ MonoBehaviour:
m_MinSize: {x: 100, y: 200}
m_MaxSize: {x: 8096, y: 16192}
vertical: 1
controlID: 126
controlID: 114
--- !u!114 &7
MonoBehaviour:
m_ObjectHideFlags: 52
@ -166,9 +166,9 @@ MonoBehaviour:
m_Position:
serializedVersion: 2
x: 0
y: 655
y: 358
width: 500
height: 314
height: 611
m_MinSize: {x: 102, y: 121}
m_MaxSize: {x: 4002, y: 4021}
m_ActualView: {fileID: 22}
@ -200,7 +200,7 @@ MonoBehaviour:
m_MinSize: {x: 100, y: 200}
m_MaxSize: {x: 8096, y: 16192}
vertical: 1
controlID: 88
controlID: 123
--- !u!114 &9
MonoBehaviour:
m_ObjectHideFlags: 52
@ -219,9 +219,9 @@ MonoBehaviour:
x: 0
y: 0
width: 500
height: 655
m_MinSize: {x: 200, y: 200}
m_MaxSize: {x: 4000, y: 4000}
height: 358
m_MinSize: {x: 202, y: 221}
m_MaxSize: {x: 4002, y: 4021}
m_ActualView: {fileID: 20}
m_Panes:
- {fileID: 20}
@ -252,7 +252,7 @@ MonoBehaviour:
m_MinSize: {x: 300, y: 200}
m_MaxSize: {x: 24288, y: 16192}
vertical: 0
controlID: 125
controlID: 17
--- !u!114 &11
MonoBehaviour:
m_ObjectHideFlags: 52
@ -272,8 +272,8 @@ MonoBehaviour:
y: 0
width: 462
height: 969
m_MinSize: {x: 275, y: 50}
m_MaxSize: {x: 4000, y: 4000}
m_MinSize: {x: 276, y: 71}
m_MaxSize: {x: 4001, y: 4021}
m_ActualView: {fileID: 19}
m_Panes:
- {fileID: 19}
@ -369,8 +369,8 @@ MonoBehaviour:
y: 0
width: 878
height: 589
m_MinSize: {x: 200, y: 200}
m_MaxSize: {x: 4000, y: 4000}
m_MinSize: {x: 201, y: 221}
m_MaxSize: {x: 4001, y: 4021}
m_ActualView: {fileID: 21}
m_Panes:
- {fileID: 21}
@ -397,9 +397,9 @@ MonoBehaviour:
m_Pos:
serializedVersion: 2
x: -1073
y: -689
y: -653
width: 1080
height: 610
height: 574
m_ViewDataDictionary: {fileID: 0}
m_OverlayCanvas:
m_LastAppliedPresetName: Default
@ -410,7 +410,7 @@ MonoBehaviour:
m_ShowGizmos: 0
m_TargetDisplay: 0
m_ClearColor: {r: 0, g: 0, b: 0, a: 0}
m_TargetSize: {x: 1080, y: 589}
m_TargetSize: {x: 1080, y: 553}
m_TextureFilterMode: 0
m_TextureHideFlags: 61
m_RenderIMGUI: 1
@ -427,8 +427,8 @@ MonoBehaviour:
vZoomLockedByDefault: 0
m_HBaseRangeMin: -540
m_HBaseRangeMax: 540
m_VBaseRangeMin: -294.5
m_VBaseRangeMax: 294.5
m_VBaseRangeMin: -276.5
m_VBaseRangeMax: 276.5
m_HAllowExceedBaseRangeMin: 1
m_HAllowExceedBaseRangeMax: 1
m_VAllowExceedBaseRangeMin: 1
@ -447,9 +447,9 @@ MonoBehaviour:
x: 0
y: 21
width: 1080
height: 589
height: 553
m_Scale: {x: 1, y: 1}
m_Translation: {x: 540, y: 294.5}
m_Translation: {x: 540, y: 276.5}
m_MarginLeft: 0
m_MarginRight: 0
m_MarginTop: 0
@ -457,12 +457,12 @@ MonoBehaviour:
m_LastShownAreaInsideMargins:
serializedVersion: 2
x: -540
y: -294.5
y: -276.5
width: 1080
height: 589
height: 553
m_MinimalGUI: 1
m_defaultScale: 1
m_LastWindowPixelSize: {x: 1080, y: 610}
m_LastWindowPixelSize: {x: 1080, y: 574}
m_ClearInEditMode: 1
m_NoCameraWarning: 1
m_LowResolutionForAspectRatios: 01000000000000000000
@ -516,8 +516,8 @@ MonoBehaviour:
m_Tooltip:
m_Pos:
serializedVersion: 2
x: -33
y: 767
x: 70
y: 672
width: 877
height: 359
m_ViewDataDictionary: {fileID: 0}
@ -550,9 +550,9 @@ MonoBehaviour:
m_IsLocked: 0
m_FolderTreeState:
scrollPos: {x: 0, y: 0}
m_SelectedIDs: ea780000
m_LastClickedID: 30954
m_ExpandedIDs: 00000000a0780000a2780000a4780000a6780000a8780000e478000000ca9a3b
m_SelectedIDs: ca780000
m_LastClickedID: 30922
m_ExpandedIDs: 00000000a0780000a2780000a4780000a6780000a8780000c478000000ca9a3b
m_RenameOverlay:
m_UserAcceptedRename: 0
m_Name:
@ -656,8 +656,8 @@ MonoBehaviour:
m_Tooltip:
m_Pos:
serializedVersion: 2
x: 1345
y: 178
x: 1448
y: 83
width: 461
height: 948
m_ViewDataDictionary: {fileID: 0}
@ -697,10 +697,10 @@ MonoBehaviour:
m_Tooltip:
m_Pos:
serializedVersion: 2
x: 845
y: 178
x: 948
y: 83
width: 498
height: 634
height: 337
m_ViewDataDictionary: {fileID: 0}
m_OverlayCanvas:
m_LastAppliedPresetName: Default
@ -708,23 +708,23 @@ MonoBehaviour:
m_SceneHierarchy:
m_TreeViewState:
scrollPos: {x: 0, y: 0}
m_SelectedIDs: fa41030048470300d64b030076420300683b03001c490300d24b0300
m_LastClickedID: 216018
m_ExpandedIDs: a84cfdff004dfdff804efdff2690fdffcc92fdffda6ffeff3870feffb871feff32fbffffaa010200ac040200ca400300
m_SelectedIDs: 46b50000
m_LastClickedID: 46406
m_ExpandedIDs: c0efffff1af0ffff9af1ffff32fbffffe0ab0000
m_RenameOverlay:
m_UserAcceptedRename: 0
m_Name: Enviroment-NonChart
m_OriginalName: Enviroment-NonChart
m_Name:
m_OriginalName:
m_EditFieldRect:
serializedVersion: 2
x: 0
y: 0
width: 0
height: 0
m_UserData: 131890
m_UserData: 0
m_IsWaitingForDelay: 0
m_IsRenaming: 0
m_OriginalEventType: 0
m_OriginalEventType: 11
m_IsRenamingFilename: 0
m_ClientGUIView: {fileID: 9}
m_SearchString:
@ -754,8 +754,8 @@ MonoBehaviour:
m_Tooltip:
m_Pos:
serializedVersion: 2
x: -33
y: 178
x: 70
y: 83
width: 877
height: 568
m_ViewDataDictionary: {fileID: 0}
@ -992,9 +992,9 @@ MonoBehaviour:
m_PlayAudio: 0
m_AudioPlay: 0
m_Position:
m_Target: {x: -37.653114, y: 49.920357, z: -199.11137}
m_Target: {x: -235.76265, y: -96.757225, z: -37.648766}
speed: 2
m_Value: {x: -37.653114, y: 49.920357, z: -199.11137}
m_Value: {x: -235.76265, y: -96.757225, z: -37.648766}
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.41212952, y: -0.07448741, z: 0.033832584, w: -0.907449}
m_Target: {x: -0.3018964, y: -0.27848974, z: 0.09269831, w: -0.9070203}
speed: 2
m_Value: {x: -0.412128, y: -0.074487135, z: 0.033832457, w: -0.90744567}
m_Value: {x: -0.30189642, y: -0.27848974, z: 0.09269832, w: -0.90702033}
m_Size:
m_Target: 1.2315754
m_Target: 103.20677
speed: 2
m_Value: 1.2315754
m_Value: 103.20677
m_Ortho:
m_Target: 0
speed: 2
@ -1092,10 +1092,10 @@ MonoBehaviour:
m_Tooltip:
m_Pos:
serializedVersion: 2
x: 845
y: 833
x: 948
y: 441
width: 498
height: 293
height: 590
m_ViewDataDictionary: {fileID: 0}
m_OverlayCanvas:
m_LastAppliedPresetName: Default