V3.3.4 LevelProbabilityPanel大于0判断逻辑修复

LevelProbabilityPanel大于0判断逻辑修复
This commit is contained in:
2023-10-05 22:56:09 +09:00
parent 198ecff461
commit 19761315f2
5 changed files with 126 additions and 99 deletions
@@ -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"}}
{"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"}}
+1 -1
View File
@@ -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"}}
{"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"}}
@@ -37,7 +37,6 @@ public class SingleLevelProbabilityPanel : MonoBehaviour
/// <param name="probability">The probability value.</param>
public void InitializeLevelProbabilityPanel(int levelName, float probability)
{
Debug.Log(levelName + " " + probability);
SetLevelName(levelName);
SetProbability(probability);
InitializeButton();
+79 -51
View File
@@ -105,64 +105,17 @@ public class TargetLevelProbabilityPanel : MonoBehaviour
while (remainCorrectionNum > 0)
{
iterationCount++;
Debug.Log(remainCorrectionNum);
remainCorrectionNum = 0;
List<int> reCorrectionIndex = new List<int>();
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 @@ public class TargetLevelProbabilityPanel : MonoBehaviour
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<int> reCorrectionIndex = new List<int>();
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]);
}
}
}