Observation多处修复
Observation显示UI修正对应新的Rotation 修正targetState长度错误,优化TargetController的Play模式 修改TargetPosition坐标从TargetBlock坐标为Firebases坐标 修改45s超时动作从加载train scene为退出游戏
This commit is contained in:
@@ -12,7 +12,7 @@ public class CommonParameterContainer : Singleton<CommonParameterContainer>
|
||||
public int timeLimit = 30;
|
||||
public bool lockCameraX = false;
|
||||
public bool lockCameraY = true;
|
||||
public bool oneHotRayTag = false;
|
||||
public bool oneHotRayTag = true;
|
||||
public bool spawnAgentInAllMap = true;
|
||||
public int spinRecordMax = 40;
|
||||
public float spinPenaltyThreshold = 10;
|
||||
|
||||
@@ -30,12 +30,11 @@ public class MLAgentsCustomController : Agent
|
||||
private RewardFunction rewardFunction;
|
||||
|
||||
// observation
|
||||
private float[] myObserve = new float[4];
|
||||
private float[] myObserve = new float[5];
|
||||
|
||||
private float[] rayTagResult;
|
||||
private float[] rayTagResultOnehot;
|
||||
private float[] rayDisResult;
|
||||
private float[] targetStates;
|
||||
private float remainTime;
|
||||
private float inFireBaseState;
|
||||
|
||||
@@ -71,7 +70,7 @@ public class MLAgentsCustomController : Agent
|
||||
{
|
||||
Debug.Log("MLAgentCustomController.OnEpisodeBegin: play mode start");
|
||||
// play mode
|
||||
targetController.PlayInitialize();
|
||||
targetController.PlayModeInitialize();
|
||||
// reset target UI
|
||||
targetUIController.ClearGamePressed();
|
||||
}
|
||||
@@ -92,6 +91,7 @@ public class MLAgentsCustomController : Agent
|
||||
myObserve[1] = transform.localPosition.y / raySensors.viewDistance;
|
||||
myObserve[2] = transform.localPosition.z / raySensors.viewDistance;
|
||||
myObserve[3] = transform.eulerAngles.y / 360f;**/
|
||||
float obsNum = 0f;
|
||||
float angleInRadians = transform.eulerAngles.y * Mathf.Deg2Rad;
|
||||
myObserve[0] = transform.localPosition.x;
|
||||
myObserve[1] = transform.localPosition.y;
|
||||
@@ -101,28 +101,35 @@ public class MLAgentsCustomController : Agent
|
||||
rayTagResult = raySensors.rayTagResult;// 探测用RayTag类型结果 float[](raySensorNum,1)
|
||||
rayTagResultOnehot = raySensors.rayTagResultOneHot; // 探测用RayTagonehot结果 List<int>[](raySensorNum*Tags,1)
|
||||
rayDisResult = raySensors.rayDisResult; // 探测用RayDis距离结果 float[](raySensorNum,1)
|
||||
targetStates = targetController.targetState; // (6) targettype, target x,y,z, firebasesAreaDiameter
|
||||
remainTime = targetController.leftTime;
|
||||
inFireBaseState = targetController.GetInAreaState();
|
||||
agentController.UpdateGunState();
|
||||
//float[] focusEnemyObserve = RaySensors.focusEnemyInfo;// 最近的Enemy情报 float[](3,1) MinEnemyIndex,x,z
|
||||
|
||||
//sensor.AddObservation(allEnemyNum); // 敌人数量 int
|
||||
sensor.AddObservation(targetStates);// (5) targettype, target x,y,z, firebasesAreaDiameter
|
||||
sensor.AddObservation(targetController.targetState);// (5) targettype, target x,y,z, firebasesAreaDiameter
|
||||
sensor.AddObservation(inFireBaseState); // (1)
|
||||
sensor.AddObservation(remainTime); // (1)
|
||||
sensor.AddObservation(agentController.gunReadyToggle); // (1) save gun is ready?
|
||||
sensor.AddObservation(myObserve); // (4)自机位置xyz+朝向 float[](4,1)
|
||||
sensor.AddObservation(myObserve); // (5)自机位置xyz+朝向 float[](5,1)
|
||||
// count observation number
|
||||
obsNum = targetController.targetState.Length+1+1+1+myObserve.Length;
|
||||
Debug.Log(obsNum);
|
||||
if (commonParamCon.oneHotRayTag)
|
||||
{
|
||||
sensor.AddObservation(rayTagResultOnehot); // 探测用RayTag结果 float[](raySensorNum,1)
|
||||
obsNum += rayTagResultOnehot.Length;
|
||||
}
|
||||
else
|
||||
{
|
||||
sensor.AddObservation(rayTagResult);
|
||||
obsNum += rayTagResult.Length;
|
||||
}
|
||||
Debug.Log(obsNum);
|
||||
sensor.AddObservation(rayDisResult); // 探测用RayDis距离结果 float[](raySensorNum,1)
|
||||
envUIController.UpdateStateText(targetStates, inFireBaseState, remainTime, agentController.gunReadyToggle, myObserve, rayTagResultOnehot, rayDisResult);
|
||||
obsNum += rayDisResult.Length;
|
||||
envUIController.UpdateStateText(targetController.targetState, inFireBaseState, remainTime, agentController.gunReadyToggle, myObserve, rayTagResultOnehot, rayDisResult);
|
||||
Debug.Log(obsNum);
|
||||
/*foreach(float aaa in rayDisResult)
|
||||
{
|
||||
Debug.Log(aaa);
|
||||
|
||||
@@ -109,7 +109,7 @@ public class SceneBlock : MonoBehaviour
|
||||
// Debug.Log("SceneBlock.Start: enemyContainerObj not found, get it by name");
|
||||
enemyContainerObj = transform.Find("EnemyContainer").gameObject;
|
||||
}
|
||||
firebasesAreaPosition = transform.position + fireBasesAreaObj.transform.position;
|
||||
firebasesAreaPosition = fireBasesAreaObj.transform.position;
|
||||
firebasesAreaScale = fireBasesAreaObj.transform.localScale.x;
|
||||
firebasesAreaDiameter = firebasesAreaScale * blockSize;
|
||||
firebasesBelong = -belongMaxPoint;
|
||||
|
||||
@@ -38,7 +38,7 @@ public class TargetController : MonoBehaviour
|
||||
[System.NonSerialized] public Targets targetType;
|
||||
[System.NonSerialized] public int gotoLevelNum;
|
||||
[System.NonSerialized] public int attackLevelNum;
|
||||
public float[] targetState = new float[5];
|
||||
[System.NonSerialized] public float[] targetState = new float[5];
|
||||
|
||||
public enum EndType
|
||||
{ Win, Lose, Running, Num };
|
||||
@@ -234,8 +234,6 @@ public class TargetController : MonoBehaviour
|
||||
|
||||
#endregion Agent Move Method
|
||||
|
||||
#region Random SceneBlock Spawn Method
|
||||
|
||||
/// <summary>
|
||||
/// Randomly spawns a scene block based on the target type.
|
||||
/// 根据目标类型随机生成场景块。
|
||||
@@ -263,7 +261,12 @@ public class TargetController : MonoBehaviour
|
||||
sceneBlockCon.nowBlock.InitBlock(environmentObj);
|
||||
}
|
||||
|
||||
#endregion Random SceneBlock Spawn Method
|
||||
private void SpawnSceneBlock(Targets targetType, int level,int blockNum, Vector3 blockPosition)
|
||||
{
|
||||
sceneBlockCon.DestroyBlock();
|
||||
sceneBlockCon.CreateNewBlock(targetType, level, blockNum, blockPosition, commonParamCon.group1Tag, commonParamCon.group2Tag);
|
||||
sceneBlockCon.InitializeBlock(environmentObj);
|
||||
}
|
||||
|
||||
#region Play Mode Method
|
||||
|
||||
@@ -279,7 +282,7 @@ public class TargetController : MonoBehaviour
|
||||
/// 该方法用于初始化游戏播放模式,包括设置目标类型、更新目标状态、更新UI显示、
|
||||
/// 将代理移动到生成区域、销毁所有敌人和场景块。
|
||||
/// </remarks>
|
||||
public void PlayInitialize()
|
||||
public void PlayModeInitialize()
|
||||
{
|
||||
targetType = Targets.Stay;
|
||||
UpdateTargetStates();
|
||||
@@ -289,35 +292,29 @@ public class TargetController : MonoBehaviour
|
||||
sceneBlockCon.DestroyBlock();
|
||||
}
|
||||
|
||||
// change to attack mode
|
||||
public void AttackModeChange(Vector3 targetPosition)
|
||||
/// <summary>
|
||||
/// Changes the target type in play mode and updates the game environment accordingly.
|
||||
/// </summary>
|
||||
/// <param name="newTargetType">The new target type to be set.</param>
|
||||
/// <param name="spawnPosition">Spawn position for scene blocks.</param>
|
||||
/// <param name="level">Level parameter for spawning scene blocks.</param>
|
||||
/// <param name="blockNum">Number of blocks to spawn.</param>
|
||||
/// <remarks>
|
||||
/// This method updates the target type to the specified new target. If a spawn position is provided, it spawns scene blocks at that position
|
||||
/// with the specified level and block number. The target states are then updated based on the new setup. The UI is also refreshed to reflect the new target type.
|
||||
/// </remarks>
|
||||
public void PlayTargetChange(Targets newTargetType, Vector3? spawnPosition = null, int level = 0, int blockNum = 0)
|
||||
{
|
||||
targetType = Targets.Attack;
|
||||
UpdateTargetStates(targetPosition);
|
||||
envUICon.UpdateTargetType(targetType);
|
||||
}
|
||||
|
||||
// change to free mode
|
||||
public void FreeModeChange()
|
||||
{
|
||||
targetType = (int)Targets.Free;
|
||||
UpdateTargetStates();
|
||||
envUICon.UpdateTargetType(targetType);
|
||||
}
|
||||
|
||||
// change to goto mode
|
||||
public void GotoModeChange(Vector3 targetPosition)
|
||||
{
|
||||
targetType = Targets.Go;
|
||||
UpdateTargetStates(targetPosition);
|
||||
envUICon.UpdateTargetType(targetType);
|
||||
}
|
||||
|
||||
// change to stay mode
|
||||
public void StayModeChange()
|
||||
{
|
||||
targetType = Targets.Stay;
|
||||
UpdateTargetStates();
|
||||
targetType = newTargetType;
|
||||
if(spawnPosition.HasValue)
|
||||
{
|
||||
SpawnSceneBlock(targetType, level, blockNum, spawnPosition.Value);
|
||||
UpdateTargetStates(spawnPosition.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
UpdateTargetStates();
|
||||
}
|
||||
envUICon.UpdateTargetType(targetType);
|
||||
}
|
||||
|
||||
@@ -344,9 +341,11 @@ public class TargetController : MonoBehaviour
|
||||
}
|
||||
else
|
||||
{
|
||||
targetState[1] = this.targetPosition.x;
|
||||
targetState[2] = this.targetPosition.y;
|
||||
targetState[3] = this.targetPosition.z;
|
||||
Vector3 fireBasePosition = sceneBlockCon.nowBlock.firebasesAreaPosition;
|
||||
Vector3 convertedPosition = fireBasePosition - this.transform.position;
|
||||
targetState[1] = convertedPosition.x;
|
||||
targetState[2] = convertedPosition.y;
|
||||
targetState[3] = convertedPosition.z;
|
||||
targetState[4] = sceneBlockCon.nowBlock.firebasesAreaDiameter;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user