浏览代码

updated cube war

/asymm-envs
Andrew Cohen 5 年前
当前提交
34f3ac64
共有 5 个文件被更改,包括 55 次插入42 次删除
  1. 2
      Project/Assets/ML-Agents/Examples/CubeWars/Prefabs/CubeWarArea.prefab
  2. 36
      Project/Assets/ML-Agents/Examples/CubeWars/Prefabs/SmallAgent.prefab
  3. 13
      Project/Assets/ML-Agents/Examples/CubeWars/Scripts/CubeWarArea.cs
  4. 40
      Project/Assets/ML-Agents/Examples/CubeWars/Scripts/SmallCubeAgent.cs
  5. 6
      config/ppo/Tennis.yaml

2
Project/Assets/ML-Agents/Examples/CubeWars/Prefabs/CubeWarArea.prefab


VectorActionSize: 0300000003000000030000000200000002000000
VectorActionDescriptions: []
VectorActionSpaceType: 0
m_Model: {fileID: 11400000, guid: fa881d0c4f6b44ea9880a781d0771fc9, type: 3}
m_Model: {fileID: 11400000, guid: 73739d3fe797a457c972705ed75362f7, type: 3}
m_InferenceDevice: 0
m_BehaviorType: 0
m_BehaviorName: LargeCubeSoldier

36
Project/Assets/ML-Agents/Examples/CubeWars/Prefabs/SmallAgent.prefab


m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8083776131842293165}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -24.8, y: 2, z: -9.559753}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children:

m_Name:
m_EditorClassIdentifier:
m_BrainParameters:
VectorObservationSize: 4
VectorObservationSize: 14
m_Model: {fileID: 11400000, guid: 697e3166f993b4e4cb890de8be9ec842, type: 3}
m_Model: {fileID: 11400000, guid: 77d026617f8254b39b58e7f514762320, type: 3}
m_InferenceDevice: 0
m_BehaviorType: 0
m_BehaviorName: SmallCubeSoldier

MaxStep: 0
area: {fileID: 0}
largeAgent: {fileID: 0}
HitPoints: 0
Teammate1: {fileID: 0}
Teammate2: {fileID: 0}
TeammateRb1: {fileID: 0}
TeammateRb2: {fileID: 0}
turnSpeed: 300
moveSpeed: 6
normalMaterial: {fileID: 2100000, guid: c9fa44c2c3f8ce74ca39a3355ea42631, type: 2}

m_Modification:
m_TransformParent: {fileID: 8081094897351109481}
m_Modifications:
- target: {fileID: 123071959092199671, guid: d40a32b30361e40b49d59bdfbbdb2e8c,
type: 3}
propertyPath: endPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 123071959092199671, guid: d40a32b30361e40b49d59bdfbbdb2e8c,
type: 3}
propertyPath: endPosition.y
value: 10
objectReference: {fileID: 0}
- target: {fileID: 123071959092199671, guid: d40a32b30361e40b49d59bdfbbdb2e8c,
type: 3}
propertyPath: endPosition.z
value: 10
objectReference: {fileID: 0}
- target: {fileID: 123071959092199671, guid: d40a32b30361e40b49d59bdfbbdb2e8c,
type: 3}
propertyPath: width
value: 0.5
objectReference: {fileID: 0}
- target: {fileID: 3343439013409978073, guid: d40a32b30361e40b49d59bdfbbdb2e8c,
type: 3}
propertyPath: m_LocalPosition.x

type: 3}
propertyPath: m_Name
value: Laser
objectReference: {fileID: 0}
- target: {fileID: 9221550522079577563, guid: d40a32b30361e40b49d59bdfbbdb2e8c,
type: 3}
propertyPath: m_Positions.Array.data[1].z
value: 1
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: d40a32b30361e40b49d59bdfbbdb2e8c, type: 3}

13
Project/Assets/ML-Agents/Examples/CubeWars/Scripts/CubeWarArea.cs


range = 1.0f;
smallAgents = GetComponentsInChildren<SmallCubeAgent>();
largeAgents = GetComponentsInChildren<LargeCubeAgent>();
smallAgents[0].Teammate1 = smallAgents[1];
smallAgents[0].Teammate2 = smallAgents[2];
smallAgents[0].TeammateRb1 = smallAgents[1].GetComponent<Rigidbody>();
smallAgents[0].TeammateRb2 = smallAgents[2].GetComponent<Rigidbody>();
smallAgents[1].Teammate1 = smallAgents[0];
smallAgents[1].Teammate2 = smallAgents[2];
smallAgents[1].TeammateRb1 = smallAgents[0].GetComponent<Rigidbody>();
smallAgents[1].TeammateRb2 = smallAgents[2].GetComponent<Rigidbody>();
smallAgents[2].Teammate1 = smallAgents[0];
smallAgents[2].Teammate2 = smallAgents[1];
smallAgents[2].TeammateRb1 = smallAgents[0].GetComponent<Rigidbody>();
smallAgents[2].TeammateRb2 = smallAgents[1].GetComponent<Rigidbody>();
}
public void AgentDied()

40
Project/Assets/ML-Agents/Examples/CubeWars/Scripts/SmallCubeAgent.cs


bool m_Shoot;
float m_ShootTime;
Rigidbody m_AgentRb;
float m_HitPoints;
[HideInInspector]
public float HitPoints;
[HideInInspector]
public SmallCubeAgent Teammate1;
[HideInInspector]
public SmallCubeAgent Teammate2;
[HideInInspector]
public Rigidbody TeammateRb1;
[HideInInspector]
public Rigidbody TeammateRb2;
// Speed of agent rotation.
public float turnSpeed;

public override void Initialize()
{
m_AgentRb = GetComponent<Rigidbody>();
//m_AgentRb.useGravity = true;
m_MyArea = area.GetComponent<CubeWarArea>();
m_LargeAgent = largeAgent.GetComponent<LargeCubeAgent>();
m_CubeWarSettings = FindObjectOfType<CubeWarSettings>();

{
sensor.AddObservation(System.Convert.ToInt32(m_Shoot));
sensor.AddObservation(System.Convert.ToInt32(m_Dead));
sensor.AddObservation(m_HitPoints);
sensor.AddObservation(HitPoints);
//Teammate 1 direction, normalized distance, hitpoints
Vector3 dirToT1 = Teammate1.transform.position - transform.position;
sensor.AddObservation(dirToT1.normalized);
sensor.AddObservation(Vector3.Distance(Teammate1.transform.position, transform.position) / 300f); //roughly normalized ditance
sensor.AddObservation(Teammate1.HitPoints);
Vector3 dirToT2 = Teammate2.transform.position - transform.position;
sensor.AddObservation(dirToT2.normalized);
sensor.AddObservation(Vector3.Distance(Teammate2.transform.position, transform.position) / 300f); //roughly normalized ditance
sensor.AddObservation(Teammate2.HitPoints);
if (m_Dead)
{
AddReward(-.001f * m_Bonus);

RaycastHit hit;
if (Physics.SphereCast(transform.position, 2f, rayDir, out hit, 28f))
{
if (hit.collider.gameObject.CompareTag("StrongSmallAgent") || hit.collider.gameObject.CompareTag("WeakSmallAgent"))
if (hit.collider.gameObject.CompareTag("StrongSmallAgent") || hit.collider.gameObject.CompareTag("WeakSmallAgent") || hit.collider.gameObject.CompareTag("DeadSmallAgent"))
{
hit.collider.gameObject.GetComponent<SmallCubeAgent>().HealAgent();
}

{
if (!m_Dead)
{
m_HitPoints -= damage;
HitPoints -= damage;
HealthStatus();
}
}

if (m_HitPoints < 1f)
if (HitPoints < 1f)
m_HitPoints = Mathf.Min(m_HitPoints + .25f, 1f);
HitPoints = Mathf.Min(HitPoints + .25f, 1f);
HealthStatus();
}
}

if (m_HitPoints <= 1f && m_HitPoints > .5f)
if (HitPoints <= 1f && HitPoints > .5f)
{
m_Dead = false;
gameObject.tag = "StrongSmallAgent";

else if (m_HitPoints <= .5f && m_HitPoints > 0.0f)
else if (HitPoints <= .5f && HitPoints > 0.0f)
{
m_Dead = false;
gameObject.tag = "WeakSmallAgent";

public override void OnEpisodeBegin()
{
m_HitPoints = 1f;
HitPoints = 1f;
HealthStatus();
m_Dead = false;
m_Shoot = false;

6
config/ppo/Tennis.yaml


gamma: 0.99
self_play:
window: 10
play_against_latest_model_ratio: 0.5
save_steps: 50000
play_against_latest_model_ratio: 0.0
save_steps: 100000
team_change: 100000
team_change: 200000
正在加载...
取消
保存