bug fix
fix target attack always win in first round.
This commit is contained in:
@@ -247,7 +247,7 @@ public class AgentWithGun : Agent
|
||||
GameObject gotHitObj = hit.transform.gameObject;//获取受到Ray撞击的对象
|
||||
gotHitObj.GetComponent<states>().ReactToHit(Damage, gameObject);
|
||||
shoot = 0;
|
||||
return targetCon.hitReward(gotHitObj.transform.position);
|
||||
return targetCon.hitEnemyReward(gotHitObj.transform.position);
|
||||
}
|
||||
}
|
||||
shoot = 0;
|
||||
|
||||
@@ -25,12 +25,12 @@ public class ParameterContainer : MonoBehaviour
|
||||
|
||||
|
||||
[Header("Dynamic Defaut Rewards")]
|
||||
[Tooltip("Hit Enemy reward")]
|
||||
public float hitRewardDefault = 60.0f;
|
||||
//[Tooltip("Hit Enemy reward")]
|
||||
//public float hitRewardDefault = 60.0f;
|
||||
[Tooltip("Free mode Hit Enemy reward")]
|
||||
public float hitTargetRewardDefault = 60.0f;
|
||||
[Tooltip("Enemy down reward")]
|
||||
public float killRewardDefault = 60.0f;
|
||||
//[Tooltip("Enemy down reward")]
|
||||
//public float killRewardDefault = 60.0f;
|
||||
[Tooltip("Enemy down in area Reward")]
|
||||
public float killTargetEnemyRewardDefault = 100.0f;
|
||||
[Tooltip("stay in firebasesArea reward")]
|
||||
@@ -53,13 +53,30 @@ public class ParameterContainer : MonoBehaviour
|
||||
[Tooltip("free Win reward")]
|
||||
public float freeWinRewardDefault = 100.0f;
|
||||
|
||||
[Header("Static Rewards")]
|
||||
[Tooltip("Nothing happened reward")]
|
||||
public float nonReward = -0.05f;
|
||||
[Tooltip("Episode Lose reward")]
|
||||
public float loseReward = -0.05f;
|
||||
[Tooltip("Agent Do shoot action reward")]
|
||||
public float shootReward = -0.1f;
|
||||
[Tooltip("Hit Not target Enemy reward")]
|
||||
public float hitReward = 30.0f;
|
||||
[Tooltip("Not Target Enemy down reward")]
|
||||
public float killReward = 40.0f;
|
||||
[Tooltip("Agent Do shoot action but gun is not read")]
|
||||
public float shootWithoutReadyReward = -0.15f;
|
||||
[Tooltip("Kill bonus reward stack to nothing happend reward")]
|
||||
public float killBonusReward = 0.0f;
|
||||
[Header("Penalty Rewards")]
|
||||
[Tooltip("Speed Penalty Reward")]
|
||||
public float speedPanalty = 0f;
|
||||
[Tooltip("view Panalty Reward")]
|
||||
public float viewPanalty = 0f;
|
||||
|
||||
[Header("Dynamic Rewards")]
|
||||
[Tooltip("Free mode Hit Enemy reward")]
|
||||
public float hitTargetReward = 60.0f;
|
||||
[Tooltip("Hit Enemy reward")]
|
||||
public float hitReward = 30.0f;
|
||||
[Tooltip("Enemy down reward")]
|
||||
public float killReward = 40.0f;
|
||||
[Tooltip("Enemy down in area Reward")]
|
||||
public float killTargetEnemyReward = 80.0f;
|
||||
[Tooltip("stay in firebasesArea reward")]
|
||||
@@ -74,24 +91,6 @@ public class ParameterContainer : MonoBehaviour
|
||||
[Tooltip("free Win reward")]
|
||||
public float freeWinReward = 50.0f;
|
||||
|
||||
|
||||
[Header("Static Rewards")]
|
||||
[Tooltip("Nothing happened reward")]
|
||||
public float nonReward = -0.05f;
|
||||
[Tooltip("Episode Lose reward")]
|
||||
public float loseReward = -0.05f;
|
||||
[Tooltip("Agent Do shoot action reward")]
|
||||
public float shootReward = -0.1f;
|
||||
[Tooltip("Agent Do shoot action but gun is not read")]
|
||||
public float shootWithoutReadyReward = -0.15f;
|
||||
[Tooltip("Kill bonus reward stack to nothing happend reward")]
|
||||
public float killBonusReward = 0.0f;
|
||||
[Header("Penalty Rewards")]
|
||||
[Tooltip("Speed Penalty Reward")]
|
||||
public float speedPanalty = 0f;
|
||||
[Tooltip("view Panalty Reward")]
|
||||
public float viewPanalty = 0f;
|
||||
|
||||
private float targetTimeBonus = 0f;
|
||||
private float areaTimeBonus = 0f;
|
||||
private float freeTimeBonus = 0f;
|
||||
@@ -131,12 +130,11 @@ public class ParameterContainer : MonoBehaviour
|
||||
targetTimeBonus = targetTimeBonusPerSec * targetCon.leftTime;
|
||||
}
|
||||
|
||||
hitReward = hitRewardDefault + freeTimeBonus;
|
||||
hitTargetReward = hitTargetRewardDefault + freeTimeBonus;
|
||||
killReward = killRewardDefault + freeTimeBonus;
|
||||
hitTargetReward = hitTargetRewardDefault + targetTimeBonus;
|
||||
killTargetEnemyReward = killTargetEnemyRewardDefault + targetTimeBonus;
|
||||
inAreaReward = inAreaRewardDefault + areaTimeBonus;
|
||||
|
||||
// Win Rewards
|
||||
goWinReward = goWinRewardDefault + targetTimeBonus;
|
||||
attackWinReward = attackWinRewardDefault + targetTimeBonus;
|
||||
defenceWinReward = defenceWinRewardDefault + targetTimeBonus;
|
||||
|
||||
@@ -51,6 +51,7 @@ public class TargetController : MonoBehaviour
|
||||
private Vector3 targetPosition;
|
||||
private Vector3 targetLocalPosition;
|
||||
private bool firstRewardFlag = true;
|
||||
private bool targetEnemySpawnFinish = false;
|
||||
private SceneBlockContainer blockCont;
|
||||
private EnemyContainer enemyCont;
|
||||
private EnvironmentUIControl envUICon;
|
||||
@@ -150,6 +151,7 @@ public class TargetController : MonoBehaviour
|
||||
blockCont.thisBlock.initBlock(EnvironmentObj);
|
||||
// set startDistance
|
||||
firstRewardFlag = true;
|
||||
targetEnemySpawnFinish = false;
|
||||
}
|
||||
else if (randTargetType > gotoProb + attackProb && randTargetType <= gotoProb + attackProb + defenceProb)
|
||||
{
|
||||
@@ -223,19 +225,6 @@ public class TargetController : MonoBehaviour
|
||||
agentCharaCon.enabled = true;
|
||||
}
|
||||
|
||||
// caulculate sceneReward if close to target then get great reward
|
||||
public float getSceneReward(float nowDistance)
|
||||
{
|
||||
if (firstRewardFlag)
|
||||
{
|
||||
(lastDistance, _) = blockCont.getAgentTargetDistanceAndInside(AgentObj.transform.position);
|
||||
firstRewardFlag = false;
|
||||
}
|
||||
float thisSceneReward = 0f;
|
||||
thisSceneReward = paramCon.distanceReward * (lastDistance - nowDistance);
|
||||
lastDistance = nowDistance;
|
||||
return thisSceneReward;
|
||||
}
|
||||
|
||||
// check over and get rewards
|
||||
// 1 = success,2 = overtime,0 = notover
|
||||
@@ -270,7 +259,7 @@ public class TargetController : MonoBehaviour
|
||||
{
|
||||
// keep on keeping on!
|
||||
|
||||
thisReward = (paramCon.inAreaReward * inArea) + getSceneReward(nowDistance);
|
||||
thisReward = (paramCon.inAreaReward * inArea) + getDistanceReward(nowDistance);
|
||||
endTypeInt = (int)EndType.Running;
|
||||
}
|
||||
break;
|
||||
@@ -278,7 +267,7 @@ public class TargetController : MonoBehaviour
|
||||
// attack
|
||||
(nowDistance, inArea) = blockCont.getAgentTargetDistanceAndInside(AgentObj.transform.position);
|
||||
envUICon.updateTargetGauge(blockCont.thisBlock.firebasesBelong, blockCont.thisBlock.belongMaxPoint);
|
||||
if (blockCont.thisBlock.firebasesBelong >= blockCont.thisBlock.belongMaxPoint && blockCont.thisBlock.getInAreaNumber(group2Tag) <= 0)
|
||||
if (blockCont.thisBlock.getInAreaNumber(group2Tag) <= 0 && targetEnemySpawnFinish)
|
||||
{
|
||||
// win
|
||||
// let the area belongs to me and kill every enmy in this area.
|
||||
@@ -286,7 +275,7 @@ public class TargetController : MonoBehaviour
|
||||
//thisReward = (paramCon.inAreaReward * inArea) + getSceneReward(nowDistance);
|
||||
endTypeInt = (int)EndType.Win;
|
||||
}
|
||||
else if (leftTime <= 0)
|
||||
else if (leftTime <= 0 && targetEnemySpawnFinish)
|
||||
{
|
||||
// time out lose
|
||||
thisReward = paramCon.loseReward;
|
||||
@@ -296,7 +285,8 @@ public class TargetController : MonoBehaviour
|
||||
else
|
||||
{
|
||||
// keep on keeping on!
|
||||
thisReward = (paramCon.inAreaReward * inArea) + getSceneReward(nowDistance);
|
||||
// thisReward = (paramCon.inAreaReward * inArea) + getDistanceReward(nowDistance);
|
||||
targetEnemySpawnFinish = true;
|
||||
endTypeInt = (int)EndType.Running;
|
||||
}
|
||||
break;
|
||||
@@ -322,7 +312,7 @@ public class TargetController : MonoBehaviour
|
||||
else
|
||||
{
|
||||
// keep on keeping on!
|
||||
thisReward = (paramCon.inAreaReward * inArea) + getSceneReward(nowDistance);
|
||||
// thisReward = (paramCon.inAreaReward * inArea) + getDistanceReward(nowDistance);
|
||||
endTypeInt = (int)EndType.Running;
|
||||
}
|
||||
break;
|
||||
@@ -354,6 +344,20 @@ public class TargetController : MonoBehaviour
|
||||
return (endTypeInt, thisReward);
|
||||
}
|
||||
|
||||
// caulculate sceneReward if close to target then get great reward
|
||||
public float getDistanceReward(float nowDistance)
|
||||
{
|
||||
if (firstRewardFlag)
|
||||
{
|
||||
(lastDistance, _) = blockCont.getAgentTargetDistanceAndInside(AgentObj.transform.position);
|
||||
firstRewardFlag = false;
|
||||
}
|
||||
float thisSceneReward = 0f;
|
||||
thisSceneReward = paramCon.distanceReward * (lastDistance - nowDistance);
|
||||
lastDistance = nowDistance;
|
||||
return thisSceneReward;
|
||||
}
|
||||
|
||||
// calculate kill reward base on killed enemy's position
|
||||
public float killReward(Vector3 enemyPosition)
|
||||
{
|
||||
@@ -372,11 +376,12 @@ public class TargetController : MonoBehaviour
|
||||
thisKillReward = paramCon.killReward;
|
||||
}
|
||||
}
|
||||
else if(targetTypeInt == (int)Targets.Free)
|
||||
else if (targetTypeInt == (int)Targets.Free)
|
||||
{
|
||||
// free mode kill
|
||||
// free mode hit
|
||||
thisKillReward = paramCon.killTargetEnemyReward;
|
||||
}else
|
||||
}
|
||||
else
|
||||
{
|
||||
// goto & defence
|
||||
thisKillReward = paramCon.killReward;
|
||||
@@ -385,7 +390,7 @@ public class TargetController : MonoBehaviour
|
||||
}
|
||||
|
||||
// calculate hit reward base on killed enemy's position and now mode
|
||||
public float hitReward(Vector3 enemyPosition)
|
||||
public float hitEnemyReward(Vector3 enemyPosition)
|
||||
{
|
||||
float thisHitReward = 0f;
|
||||
if (targetTypeInt == (int)Targets.Attack)
|
||||
|
||||
Reference in New Issue
Block a user