From 19761315f29fae2cf7c7e02f4c45e2f4c3f1542b Mon Sep 17 00:00:00 2001 From: Koha9 Date: Thu, 5 Oct 2023 22:56:09 +0900 Subject: [PATCH] =?UTF-8?q?V3.3.4=20LevelProbabilityPanel=E5=A4=A7?= =?UTF-8?q?=E4=BA=8E0=E5=88=A4=E6=96=AD=E9=80=BB=E8=BE=91=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit LevelProbabilityPanel大于0判断逻辑修复 --- .../ML-Agents/Timers/StartScene_timers.json | 2 +- Assets/ML-Agents/Timers/Train_timers.json | 2 +- Assets/Script/SingleLevelProbabilityPanel.cs | 1 - Assets/TargetLevelProbabilityPanel.cs | 130 +++++++++++------- UserSettings/Layouts/default-2021.dwlt | 90 ++++++------ 5 files changed, 126 insertions(+), 99 deletions(-) diff --git a/Assets/ML-Agents/Timers/StartScene_timers.json b/Assets/ML-Agents/Timers/StartScene_timers.json index 6fb4511..a05f389 100644 --- a/Assets/ML-Agents/Timers/StartScene_timers.json +++ b/Assets/ML-Agents/Timers/StartScene_timers.json @@ -1 +1 @@ -{"count":1,"self":6.0113204,"total":6.0228211,"children":{"InitializeActuators":{"count":2,"self":0.0010002,"total":0.0010002,"children":null},"InitializeSensors":{"count":2,"self":0.0010004,"total":0.0010004,"children":null},"AgentSendState":{"count":9,"self":0.0004999,"total":0.0029998,"children":{"CollectObservations":{"count":9,"self":0.0014984999999999998,"total":0.0014984999999999998,"children":null},"WriteActionMask":{"count":9,"self":0,"total":0,"children":null},"RequestDecision":{"count":9,"self":0.0010014,"total":0.0010014,"children":null}}},"DecideAction":{"count":9,"self":0.0009999,"total":0.0009999,"children":null},"AgentAct":{"count":9,"self":0.0055004,"total":0.0055004,"children":null}},"gauges":{},"metadata":{"timer_format_version":"0.1.0","start_time_seconds":"1696497364","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-q2quha7JFq52w-SUtj3vv -hubSessionId 61f6b54c-8d4c-45ec-a505-47188486c77c -accessToken d9LTYkb4CwoKU0gEjpj65W_Ohjmpt7x9dRCoXTK1U7c00ef","communication_protocol_version":"1.5.0","com.unity.ml-agents_version":"2.0.1","scene_name":"StartScene","end_time_seconds":"1696497370"}} \ No newline at end of file +{"count":1,"self":8.25924,"total":8.3077335,"children":{"InitializeActuators":{"count":2,"self":0.0010007,"total":0.0010007,"children":null},"InitializeSensors":{"count":2,"self":0.001501,"total":0.001501,"children":null},"AgentSendState":{"count":151,"self":0.0014988999999999998,"total":0.0125058,"children":{"CollectObservations":{"count":151,"self":0.0090066,"total":0.0090066,"children":null},"WriteActionMask":{"count":151,"self":0.0005009,"total":0.0005009,"children":null},"RequestDecision":{"count":151,"self":0.0014994,"total":0.0014994,"children":null}}},"DecideAction":{"count":151,"self":0.0010014,"total":0.0010014,"children":null},"AgentAct":{"count":151,"self":0.032485,"total":0.032485,"children":null}},"gauges":{},"metadata":{"timer_format_version":"0.1.0","start_time_seconds":"1696510666","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-q2quha7JFq52w-SUtj3vv -hubSessionId 61f6b54c-8d4c-45ec-a505-47188486c77c -accessToken MD8iouPZlC7chsDZh-2OfbaNG8DDnFy36WE1syqyLNg00ef","communication_protocol_version":"1.5.0","com.unity.ml-agents_version":"2.0.1","scene_name":"StartScene","end_time_seconds":"1696510675"}} \ No newline at end of file diff --git a/Assets/ML-Agents/Timers/Train_timers.json b/Assets/ML-Agents/Timers/Train_timers.json index 846e3e3..d4c54b5 100644 --- a/Assets/ML-Agents/Timers/Train_timers.json +++ b/Assets/ML-Agents/Timers/Train_timers.json @@ -1 +1 @@ -{"count":1,"self":4.4885076,"total":4.5005076,"children":{"InitializeActuators":{"count":2,"self":0.0010002,"total":0.0010002,"children":null},"InitializeSensors":{"count":2,"self":0.0010004,"total":0.0010004,"children":null},"AgentSendState":{"count":9,"self":0.0004999,"total":0.0029998,"children":{"CollectObservations":{"count":9,"self":0.0014984999999999998,"total":0.0014984999999999998,"children":null},"WriteActionMask":{"count":9,"self":0,"total":0,"children":null},"RequestDecision":{"count":9,"self":0.0010014,"total":0.0010014,"children":null}}},"DecideAction":{"count":9,"self":0.0009999,"total":0.0009999,"children":null},"AgentAct":{"count":9,"self":0.0055004,"total":0.0055004,"children":null}},"gauges":{},"metadata":{"timer_format_version":"0.1.0","start_time_seconds":"1696497364","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-q2quha7JFq52w-SUtj3vv -hubSessionId 61f6b54c-8d4c-45ec-a505-47188486c77c -accessToken d9LTYkb4CwoKU0gEjpj65W_Ohjmpt7x9dRCoXTK1U7c00ef","communication_protocol_version":"1.5.0","com.unity.ml-agents_version":"2.0.1","scene_name":"Train","end_time_seconds":"1696497369"}} \ No newline at end of file +{"count":1,"self":7.384512,"total":7.4340082,"children":{"InitializeActuators":{"count":2,"self":0.0010007,"total":0.0010007,"children":null},"InitializeSensors":{"count":2,"self":0.001501,"total":0.001501,"children":null},"AgentSendState":{"count":151,"self":0.0014988999999999998,"total":0.0125058,"children":{"CollectObservations":{"count":151,"self":0.0090066,"total":0.0090066,"children":null},"WriteActionMask":{"count":151,"self":0.0005009,"total":0.0005009,"children":null},"RequestDecision":{"count":151,"self":0.0014994,"total":0.0014994,"children":null}}},"DecideAction":{"count":151,"self":0.0010014,"total":0.0010014,"children":null},"AgentAct":{"count":151,"self":0.032485,"total":0.032485,"children":null}},"gauges":{},"metadata":{"timer_format_version":"0.1.0","start_time_seconds":"1696510666","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-q2quha7JFq52w-SUtj3vv -hubSessionId 61f6b54c-8d4c-45ec-a505-47188486c77c -accessToken MD8iouPZlC7chsDZh-2OfbaNG8DDnFy36WE1syqyLNg00ef","communication_protocol_version":"1.5.0","com.unity.ml-agents_version":"2.0.1","scene_name":"Train","end_time_seconds":"1696510674"}} \ No newline at end of file diff --git a/Assets/Script/SingleLevelProbabilityPanel.cs b/Assets/Script/SingleLevelProbabilityPanel.cs index 74334bd..58cb587 100644 --- a/Assets/Script/SingleLevelProbabilityPanel.cs +++ b/Assets/Script/SingleLevelProbabilityPanel.cs @@ -37,7 +37,6 @@ public void InitializeLevelProbabilityPanel(string levelName, float probability) /// The probability value. public void InitializeLevelProbabilityPanel(int levelName, float probability) { - Debug.Log(levelName + " " + probability); SetLevelName(levelName); SetProbability(probability); InitializeButton(); diff --git a/Assets/TargetLevelProbabilityPanel.cs b/Assets/TargetLevelProbabilityPanel.cs index d26d6a1..4eae2b3 100644 --- a/Assets/TargetLevelProbabilityPanel.cs +++ b/Assets/TargetLevelProbabilityPanel.cs @@ -105,64 +105,17 @@ private void OnSliderValueChange(float value, int exceptedIndex) while (remainCorrectionNum > 0) { iterationCount++; - Debug.Log(remainCorrectionNum); - remainCorrectionNum = 0; - List reCorrectionIndex = new List(); - int lastReCorrectionIndex = 0; - float underZeroExtraValueAfterCorrected = 0; - for (int i = 0; i < panelNum; ++i) - { - // if the panel is the changed one - if (i == exceptedIndex) - { - correctionValues[i] = 0; - continue; - } - // if the panel is locked or the probability value is 0 or the probability value is equal to the correction value - if (singleLevelPanels[i].IsLocked || singleLevelPanels[i].ProbabilityValue <= 0) - { - correctionValues[i] = 0; - } - else if (singleLevelPanels[i].ProbabilityValue == correctionValues[i]) - { - underZeroExtraValueAfterCorrected += correctionValues[i]; - } - else if (singleLevelPanels[i].ProbabilityValue - correctionValues[i] < 0) - { - underZeroExtraValueAfterCorrected += correctionValues[i]; - correctionValues[i] = singleLevelPanels[i].ProbabilityValue; - remainCorrectionNum++; - } - else - { - lastReCorrectionIndex = i; - reCorrectionIndex.Add(i); - } - } - foreach (int index in reCorrectionIndex) - { - float newAverageCorrectionValue = (extraValue - underZeroExtraValueAfterCorrected) / reCorrectionIndex.Count; - // - if (index == lastReCorrectionIndex) - { - correctionValues[index] = extraValue - (newAverageCorrectionValue * (reCorrectionIndex.Count - 1)); - } - else - { - correctionValues[index] = newAverageCorrectionValue; - } - } + (correctionValues, remainCorrectionNum) = reCalculateCorrectionValues(correctionValues, exceptedIndex, value, extraValue); + // protect the infinite loop if (iterationCount >= 100) { + Debug.LogError("Infinite loop detected!"); break; } } // applicate the value to all unlocked panels excepted the changed one - for (int i = 0; i < panelNum; i++) - { - singleLevelPanels[i].SetProbability(i == exceptedIndex ? value : singleLevelPanels[i].ProbabilityValue - correctionValues[i]); - } + applyCorrectionValue(correctionValues); enableSliderListener(); } @@ -174,4 +127,79 @@ private void enableSliderListener() singleLevelPanels[i].probabilitySlider.onValueChanged.AddListener((value) => OnSliderValueChange(value, tempIndex)); } } + + private (float[], int) reCalculateCorrectionValues(float[] correctionValues, int exceptedIndex, float value, float extraValue) + { + int remainCorrectionNum = 0; + List reCorrectionIndex = new List(); + int lastReCorrectionIndex = 0; + float underZeroExtraValueAfterCorrected = 0; + for (int i = 0; i < panelNum; ++i) + { + // if the panel is the changed one + if (i == exceptedIndex) + { + correctionValues[i] = singleLevelPanels[i].ProbabilityValue - value; + continue; + } + // if the panel is locked or the probability value is 0 or the probability value is equal to the correction value + if (singleLevelPanels[i].IsLocked || singleLevelPanels[i].ProbabilityValue <= 0) + { + correctionValues[i] = 0; + } + else if (singleLevelPanels[i].ProbabilityValue == correctionValues[i]) + { + underZeroExtraValueAfterCorrected += correctionValues[i]; + } + else if (singleLevelPanels[i].ProbabilityValue - correctionValues[i] < 0) + { + underZeroExtraValueAfterCorrected += correctionValues[i]; + correctionValues[i] = singleLevelPanels[i].ProbabilityValue; + remainCorrectionNum++; + } + else + { + lastReCorrectionIndex = i; + reCorrectionIndex.Add(i); + } + } + foreach (int index in reCorrectionIndex) + { + float newAverageCorrectionValue = (extraValue - underZeroExtraValueAfterCorrected) / reCorrectionIndex.Count; + if (index == lastReCorrectionIndex) + { + correctionValues[index] = extraValue - (newAverageCorrectionValue * (reCorrectionIndex.Count - 1)); + if (singleLevelPanels[index].ProbabilityValue - correctionValues[index] < 0) + { + correctionValues[index] = singleLevelPanels[index].ProbabilityValue; + remainCorrectionNum++; + } + } + else + { + correctionValues[index] = newAverageCorrectionValue; + if (singleLevelPanels[index].ProbabilityValue - correctionValues[index] < 0) + { + correctionValues[index] = singleLevelPanels[index].ProbabilityValue; + remainCorrectionNum++; + } + } + } + return (correctionValues, remainCorrectionNum); + } + + private void applyCorrectionValue(float[] correctionValues) + { + for (int i = 0; i < panelNum; i++) + { + if (singleLevelPanels[i].ProbabilityValue - correctionValues[i] < 0) + { + Debug.LogWarning("Probability value is less than 0"); + Debug.Log(i); + Debug.Log(singleLevelPanels[i].ProbabilityValue); + Debug.Log(correctionValues[i]); + } + singleLevelPanels[i].SetProbability(singleLevelPanels[i].ProbabilityValue - correctionValues[i]); + } + } } \ No newline at end of file diff --git a/UserSettings/Layouts/default-2021.dwlt b/UserSettings/Layouts/default-2021.dwlt index a3a39da..8e0a994 100644 --- a/UserSettings/Layouts/default-2021.dwlt +++ b/UserSettings/Layouts/default-2021.dwlt @@ -14,8 +14,8 @@ MonoBehaviour: m_EditorClassIdentifier: m_PixelRect: serializedVersion: 2 - x: 65 - y: 43 + x: -217 + y: 233 width: 1855 height: 1037 m_ShowMode: 4 @@ -23,7 +23,7 @@ MonoBehaviour: m_RootView: {fileID: 2} m_MinSize: {x: 875, y: 300} m_MaxSize: {x: 10000, y: 10000} - m_Maximized: 1 + m_Maximized: 0 --- !u!114 &2 MonoBehaviour: m_ObjectHideFlags: 52 @@ -120,7 +120,7 @@ MonoBehaviour: m_MinSize: {x: 300, y: 200} m_MaxSize: {x: 24288, y: 16192} vertical: 0 - controlID: 73 + controlID: 119 --- !u!114 &6 MonoBehaviour: m_ObjectHideFlags: 52 @@ -140,12 +140,12 @@ MonoBehaviour: serializedVersion: 2 x: 0 y: 0 - width: 1048 + width: 1047 height: 987 m_MinSize: {x: 100, y: 200} m_MaxSize: {x: 8096, y: 16192} vertical: 1 - controlID: 74 + controlID: 120 --- !u!114 &7 MonoBehaviour: m_ObjectHideFlags: 52 @@ -163,7 +163,7 @@ MonoBehaviour: serializedVersion: 2 x: 0 y: 0 - width: 1048 + width: 1047 height: 615 m_MinSize: {x: 201, y: 221} m_MaxSize: {x: 4001, y: 4021} @@ -190,7 +190,7 @@ MonoBehaviour: serializedVersion: 2 x: 0 y: 615 - width: 1048 + width: 1047 height: 372 m_MinSize: {x: 231, y: 271} m_MaxSize: {x: 10001, y: 10021} @@ -217,14 +217,14 @@ MonoBehaviour: - {fileID: 11} m_Position: serializedVersion: 2 - x: 1048 + x: 1047 y: 0 - width: 433 + width: 434 height: 987 m_MinSize: {x: 100, y: 200} m_MaxSize: {x: 8096, y: 16192} vertical: 1 - controlID: 54 + controlID: 52 --- !u!114 &10 MonoBehaviour: m_ObjectHideFlags: 52 @@ -242,7 +242,7 @@ MonoBehaviour: serializedVersion: 2 x: 0 y: 0 - width: 433 + width: 434 height: 443 m_MinSize: {x: 200, y: 200} m_MaxSize: {x: 4000, y: 4000} @@ -268,7 +268,7 @@ MonoBehaviour: serializedVersion: 2 x: 0 y: 443 - width: 433 + width: 434 height: 544 m_MinSize: {x: 102, y: 121} m_MaxSize: {x: 4002, y: 4021} @@ -324,9 +324,9 @@ MonoBehaviour: m_Tooltip: m_Pos: serializedVersion: 2 - x: 65 - y: 73 - width: 1047 + x: -217 + y: 263 + width: 1046 height: 594 m_ViewDataDictionary: {fileID: 0} m_OverlayCanvas: @@ -562,9 +562,9 @@ MonoBehaviour: m_PlayAudio: 0 m_AudioPlay: 0 m_Position: - m_Target: {x: 271.76544, y: 474.12607, z: -1.6757603} + m_Target: {x: 224.20319, y: 389.57086, z: -1.7488194} speed: 2 - m_Value: {x: 271.76544, y: 474.12607, z: -1.6757603} + m_Value: {x: 224.20319, y: 389.57086, z: -1.7488194} m_RenderMode: 0 m_CameraMode: drawMode: 0 @@ -662,9 +662,9 @@ MonoBehaviour: m_Tooltip: m_Pos: serializedVersion: 2 - x: 65 + x: 1920 y: 73 - width: 1047 + width: 1083 height: 594 m_ViewDataDictionary: {fileID: 0} m_OverlayCanvas: @@ -676,7 +676,7 @@ MonoBehaviour: m_ShowGizmos: 0 m_TargetDisplay: 0 m_ClearColor: {r: 0, g: 0, b: 0, a: 0} - m_TargetSize: {x: 1047, y: 573} + m_TargetSize: {x: 1083, y: 573} m_TextureFilterMode: 0 m_TextureHideFlags: 61 m_RenderIMGUI: 1 @@ -691,8 +691,8 @@ MonoBehaviour: m_VRangeLocked: 0 hZoomLockedByDefault: 0 vZoomLockedByDefault: 0 - m_HBaseRangeMin: -523.5 - m_HBaseRangeMax: 523.5 + m_HBaseRangeMin: -541.5 + m_HBaseRangeMax: 541.5 m_VBaseRangeMin: -286.5 m_VBaseRangeMax: 286.5 m_HAllowExceedBaseRangeMin: 1 @@ -712,23 +712,23 @@ MonoBehaviour: serializedVersion: 2 x: 0 y: 21 - width: 1047 + width: 1083 height: 573 m_Scale: {x: 1, y: 1} - m_Translation: {x: 523.5, y: 286.5} + m_Translation: {x: 541.5, y: 286.5} m_MarginLeft: 0 m_MarginRight: 0 m_MarginTop: 0 m_MarginBottom: 0 m_LastShownAreaInsideMargins: serializedVersion: 2 - x: -523.5 + x: -541.5 y: -286.5 - width: 1047 + width: 1083 height: 573 m_MinimalGUI: 1 m_defaultScale: 1 - m_LastWindowPixelSize: {x: 1047, y: 594} + m_LastWindowPixelSize: {x: 1083, y: 594} m_ClearInEditMode: 1 m_NoCameraWarning: 1 m_LowResolutionForAspectRatios: 01000000000000000000 @@ -754,9 +754,9 @@ MonoBehaviour: m_Tooltip: m_Pos: serializedVersion: 2 - x: 65 - y: 688 - width: 1047 + x: -217 + y: 878 + width: 1046 height: 351 m_ViewDataDictionary: {fileID: 0} m_OverlayCanvas: @@ -775,21 +775,21 @@ MonoBehaviour: m_SkipHidden: 0 m_SearchArea: 1 m_Folders: - - Assets + - Assets/Script m_Globs: [] m_OriginalText: m_ViewMode: 1 m_StartGridSize: 16 m_LastFolders: - - Assets + - Assets/DelthorGames/AKM/Models m_LastFoldersGridSize: 16 m_LastProjectPath: C:\Users\UCUNI\OneDrive\Unity\ML-Agents\Aimbot-ParallelEnv m_LockTracker: m_IsLocked: 0 m_FolderTreeState: scrollPos: {x: 0, y: 0} - m_SelectedIDs: 50760000 - m_LastClickedID: 30288 + m_SelectedIDs: 06ca9a3b + m_LastClickedID: 1000000006 m_ExpandedIDs: 000000002c7600002e76000030760000327600003476000036760000387600003a7600003c7600003e76000040760000427600004476000046760000487600004a7600004c7600004e7600005076000000ca9a3bffffff7f m_RenameOverlay: m_UserAcceptedRename: 0 @@ -870,7 +870,7 @@ MonoBehaviour: m_Icon: {fileID: 0} m_ResourceFile: m_NewAssetIndexInList: -1 - m_ScrollPosition: {x: 0, y: 64} + m_ScrollPosition: {x: 0, y: 0} m_GridSize: 16 m_SkipHiddenPackages: 0 m_DirectoriesAreaWidth: 355 @@ -922,9 +922,9 @@ MonoBehaviour: m_Tooltip: m_Pos: serializedVersion: 2 - x: 1113 - y: 73 - width: 431 + x: 830 + y: 263 + width: 432 height: 422 m_ViewDataDictionary: {fileID: 0} m_OverlayCanvas: @@ -933,7 +933,7 @@ MonoBehaviour: m_SceneHierarchy: m_TreeViewState: scrollPos: {x: 0, y: 0} - m_SelectedIDs: f8150000 + m_SelectedIDs: 36250000 m_LastClickedID: 0 m_ExpandedIDs: 32fbffff m_RenameOverlay: @@ -979,9 +979,9 @@ MonoBehaviour: m_Tooltip: m_Pos: serializedVersion: 2 - x: 1113 - y: 516 - width: 431 + x: 830 + y: 706 + width: 432 height: 523 m_ViewDataDictionary: {fileID: 0} m_OverlayCanvas: @@ -1035,8 +1035,8 @@ MonoBehaviour: m_Tooltip: m_Pos: serializedVersion: 2 - x: 1546 - y: 73 + x: 1264 + y: 263 width: 373 height: 966 m_ViewDataDictionary: {fileID: 0}