浏览代码

Merge branch 'soccer-2v1' into asymm-envs

/asymm-envs
Andrew Cohen 4 年前
当前提交
e2d68e4f
共有 5 个文件被更改,包括 51 次插入54 次删除
  1. 24
      Project/Assets/ML-Agents/Examples/Tennis/Prefabs/TennisArea.prefab
  2. 39
      Project/Assets/ML-Agents/Examples/Tennis/Scenes/Tennis.unity
  3. 22
      Project/Assets/ML-Agents/Examples/Tennis/Scripts/HitWall.cs
  4. 12
      Project/Assets/ML-Agents/Examples/Tennis/Scripts/TennisAgent.cs
  5. 8
      Project/Assets/ML-Agents/Examples/Tennis/Scripts/TennisArea.cs

24
Project/Assets/ML-Agents/Examples/Tennis/Prefabs/TennisArea.prefab


m_Name:
m_EditorClassIdentifier:
m_BrainParameters:
vectorObservationSize: 10
vectorObservationSize: 9
m_Model: {fileID: 11400000, guid: af0e636edb8584db08624f42c5f71f97, type: 3}
m_Model: {fileID: 11400000, guid: d6c5e749e4ceb4cf79640a5955706d3d, type: 3}
m_InferenceDevice: 0
m_BehaviorType: 0
m_BehaviorName: Tennis

m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1485570486708108}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: -5.9507, y: -3, z: 0}
m_LocalScale: {x: 1.0831101, y: 1, z: 1.1727886}
m_LocalPosition: {x: -6.07, y: -1.4, z: 0}
m_LocalScale: {x: 1.1, y: 1, z: 1.2}
m_Children: []
m_Father: {fileID: 4275308033819996}
m_RootOrder: 0

m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1485570486708108}
m_Material: {fileID: 0}
m_Material: {fileID: 13400000, guid: 56162663048874fd4b10e065f9cf78b7, type: 2}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2

m_GameObject: {fileID: 1600389029549348}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: -7.5, z: 0}
m_LocalScale: {x: 0.01, y: 0.01, z: 0.01}
m_LocalScale: {x: 0.02, y: 0.02, z: 0.02}
m_Children:
- {fileID: 4859823443517042}
- {fileID: 4821769212579210}

m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1730923431341952}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 6.07, y: -3, z: 0}
m_LocalScale: {x: 1.0919912, y: 1, z: 1.1119019}
m_LocalPosition: {x: 6.07, y: -1.4, z: 0}
m_LocalScale: {x: 1.09, y: 1, z: 1.2}
m_Children: []
m_Father: {fileID: 4275308033819996}
m_RootOrder: 1

m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1730923431341952}
m_Material: {fileID: 0}
m_Material: {fileID: 13400000, guid: 56162663048874fd4b10e065f9cf78b7, type: 2}
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2

m_Name:
m_EditorClassIdentifier:
m_BrainParameters:
vectorObservationSize: 10
vectorObservationSize: 9
m_Model: {fileID: 11400000, guid: af0e636edb8584db08624f42c5f71f97, type: 3}
m_Model: {fileID: 11400000, guid: d6c5e749e4ceb4cf79640a5955706d3d, type: 3}
m_InferenceDevice: 0
m_BehaviorType: 0
m_BehaviorName: Tennis

m_GameObject: {fileID: 1969551055586186}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: -4, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_LocalScale: {x: 2, y: 2, z: 2}
m_Children:
- {fileID: 4733128113887812}
- {fileID: 4535263776590958}

39
Project/Assets/ML-Agents/Examples/Tennis/Scenes/Tennis.unity


objectReference: {fileID: 0}
- target: {fileID: 4172342666475122, guid: 812997c7bc2544b6f927ff684c03450f, type: 3}
propertyPath: m_LocalPosition.x
value: 44.4
value: 60
objectReference: {fileID: 0}
- target: {fileID: 4172342666475122, guid: 812997c7bc2544b6f927ff684c03450f, type: 3}
propertyPath: m_LocalPosition.y

objectReference: {fileID: 0}
- target: {fileID: 4172342666475122, guid: 812997c7bc2544b6f927ff684c03450f, type: 3}
propertyPath: m_LocalPosition.x
value: 44.4
value: 60
objectReference: {fileID: 0}
- target: {fileID: 4172342666475122, guid: 812997c7bc2544b6f927ff684c03450f, type: 3}
propertyPath: m_LocalPosition.y

objectReference: {fileID: 0}
- target: {fileID: 4172342666475122, guid: 812997c7bc2544b6f927ff684c03450f, type: 3}
propertyPath: m_LocalPosition.x
value: -45.6
value: -60
objectReference: {fileID: 0}
- target: {fileID: 4172342666475122, guid: 812997c7bc2544b6f927ff684c03450f, type: 3}
propertyPath: m_LocalPosition.y

objectReference: {fileID: 0}
- target: {fileID: 4172342666475122, guid: 812997c7bc2544b6f927ff684c03450f, type: 3}
propertyPath: m_LocalPosition.x
value: -45.6
value: -60
objectReference: {fileID: 0}
- target: {fileID: 4172342666475122, guid: 812997c7bc2544b6f927ff684c03450f, type: 3}
propertyPath: m_LocalPosition.y

objectReference: {fileID: 0}
- target: {fileID: 4172342666475122, guid: 812997c7bc2544b6f927ff684c03450f, type: 3}
propertyPath: m_LocalPosition.x
value: -45.6
value: -60
objectReference: {fileID: 0}
- target: {fileID: 4172342666475122, guid: 812997c7bc2544b6f927ff684c03450f, type: 3}
propertyPath: m_LocalPosition.y

objectReference: {fileID: 0}
- target: {fileID: 4172342666475122, guid: 812997c7bc2544b6f927ff684c03450f, type: 3}
propertyPath: m_LocalPosition.x
value: 44.4
value: 60
objectReference: {fileID: 0}
- target: {fileID: 4172342666475122, guid: 812997c7bc2544b6f927ff684c03450f, type: 3}
propertyPath: m_LocalPosition.y

objectReference: {fileID: 0}
- target: {fileID: 4172342666475122, guid: 812997c7bc2544b6f927ff684c03450f, type: 3}
propertyPath: m_LocalPosition.x
value: -45.6
value: -60
objectReference: {fileID: 0}
- target: {fileID: 4172342666475122, guid: 812997c7bc2544b6f927ff684c03450f, type: 3}
propertyPath: m_LocalPosition.y

m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 957430531}
m_LocalRotation: {x: 0.13052616, y: 0, z: 0, w: 0.9914449}
m_LocalPosition: {x: 0, y: 6.25, z: -25.6}
m_LocalRotation: {x: 0.17364816, y: 0, z: 0, w: 0.9848078}
m_LocalPosition: {x: 0, y: 15, z: -42}
m_LocalEulerAnglesHint: {x: 15, y: 0, z: 0}
m_LocalEulerAnglesHint: {x: 20, y: 0, z: 0}
--- !u!1001 &978771510
PrefabInstance:
m_ObjectHideFlags: 0

propertyPath: m_IsActive
value: 1
objectReference: {fileID: 0}
- target: {fileID: 1969551055586186, guid: 812997c7bc2544b6f927ff684c03450f, type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
value: -45.6
value: -60
objectReference: {fileID: 0}
- target: {fileID: 4172342666475122, guid: 812997c7bc2544b6f927ff684c03450f, type: 3}
propertyPath: m_LocalPosition.y

- target: {fileID: 1541947554534326, guid: 812997c7bc2544b6f927ff684c03450f, type: 3}
propertyPath: m_Name
value: TennisArea (3)
objectReference: {fileID: 0}
- target: {fileID: 1541947554534326, guid: 812997c7bc2544b6f927ff684c03450f, type: 3}
propertyPath: m_IsActive
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4172342666475122, guid: 812997c7bc2544b6f927ff684c03450f, type: 3}
propertyPath: m_LocalPosition.x

objectReference: {fileID: 0}
- target: {fileID: 4172342666475122, guid: 812997c7bc2544b6f927ff684c03450f, type: 3}
propertyPath: m_LocalPosition.x
value: 44.4
value: 60
objectReference: {fileID: 0}
- target: {fileID: 4172342666475122, guid: 812997c7bc2544b6f927ff684c03450f, type: 3}
propertyPath: m_LocalPosition.y

objectReference: {fileID: 0}
- target: {fileID: 4172342666475122, guid: 812997c7bc2544b6f927ff684c03450f, type: 3}
propertyPath: m_LocalPosition.x
value: 44.4
value: 60
objectReference: {fileID: 0}
- target: {fileID: 4172342666475122, guid: 812997c7bc2544b6f927ff684c03450f, type: 3}
propertyPath: m_LocalPosition.y

objectReference: {fileID: 0}
- target: {fileID: 4172342666475122, guid: 812997c7bc2544b6f927ff684c03450f, type: 3}
propertyPath: m_LocalPosition.x
value: 44.4
value: 60
objectReference: {fileID: 0}
- target: {fileID: 4172342666475122, guid: 812997c7bc2544b6f927ff684c03450f, type: 3}
propertyPath: m_LocalPosition.y

m_Name:
m_EditorClassIdentifier:
gravityMultiplier: 1
monitorVerticalOffset: 0
fixedDeltaTime: 0.02
maximumDeltaTime: 0.33333334
solverIterations: 6

objectReference: {fileID: 0}
- target: {fileID: 4172342666475122, guid: 812997c7bc2544b6f927ff684c03450f, type: 3}
propertyPath: m_LocalPosition.x
value: -45.6
value: -60
objectReference: {fileID: 0}
- target: {fileID: 4172342666475122, guid: 812997c7bc2544b6f927ff684c03450f, type: 3}
propertyPath: m_LocalPosition.y

22
Project/Assets/ML-Agents/Examples/Tennis/Scripts/HitWall.cs


FloorAHit,
FloorBHit
}
[HideInInspector]
public FloorHit LastFloorHit;
FloorHit m_LastFloorHit;
TennisArea m_Area;
TennisAgent m_AgentA;

public void ResetPoint()
{
LastFloorHit = FloorHit.Service;
m_LastFloorHit = FloorHit.Service;
m_LastAgentHit = -1;
}

if (collision.gameObject.name == "wallA")
{
// Agent A hits into wall or agent B hit a winner
if (m_LastAgentHit == 0 || LastFloorHit == FloorHit.FloorAHit)
if (m_LastAgentHit == 0 || m_LastFloorHit == FloorHit.FloorAHit)
{
AgentBWins();
}

else if (collision.gameObject.name == "wallB")
{
// Agent B hits into wall or agent A hit a winner
if (m_LastAgentHit == 1 || LastFloorHit == FloorHit.FloorBHit)
if (m_LastAgentHit == 1 || m_LastFloorHit == FloorHit.FloorBHit)
{
AgentAWins();
}

else if (collision.gameObject.name == "floorA")
{
// Agent A hits into floor, double bounce or service
if (m_LastAgentHit == 0 || LastFloorHit == FloorHit.FloorAHit || LastFloorHit == FloorHit.Service)
if (m_LastAgentHit == 0 || m_LastFloorHit == FloorHit.FloorAHit || m_LastFloorHit == FloorHit.Service)
LastFloorHit = FloorHit.FloorAHit;
m_LastFloorHit = FloorHit.FloorAHit;
if (m_LastAgentHit == 1 || LastFloorHit == FloorHit.FloorBHit || LastFloorHit == FloorHit.Service)
if (m_LastAgentHit == 1 || m_LastFloorHit == FloorHit.FloorBHit || m_LastFloorHit == FloorHit.Service)
LastFloorHit = FloorHit.FloorBHit;
m_LastFloorHit = FloorHit.FloorBHit;
}
}
}

{
m_LastAgentHit = 0;
LastFloorHit = FloorHit.FloorHitUnset;
m_LastFloorHit = FloorHit.FloorHitUnset;
}
}
else if (collision.gameObject.name == "AgentB")

else
{
m_LastAgentHit = 1;
LastFloorHit = FloorHit.FloorHitUnset;
m_LastFloorHit = FloorHit.FloorHitUnset;
}
}
}

12
Project/Assets/ML-Agents/Examples/Tennis/Scripts/TennisAgent.cs


Text m_TextComponent;
Rigidbody m_AgentRb;
Rigidbody m_BallRb;
HitWall m_BallScript;
TennisArea m_Area;
float m_InvertMult;
FloatPropertiesChannel m_ResetParams;

{
m_AgentRb = GetComponent<Rigidbody>();
m_BallRb = ball.GetComponent<Rigidbody>();
m_BallScript = ball.GetComponent<HitWall>();
m_Area = myArea.GetComponent<TennisArea>();
var canvas = GameObject.Find(k_CanvasName);
GameObject scoreBoard;

sensor.AddObservation(m_BallRb.velocity.y);
sensor.AddObservation(m_InvertMult * gameObject.transform.rotation.z);
if (m_BallScript.LastFloorHit == HitWall.FloorHit.FloorHitUnset)
{
sensor.AddObservation(1.0f);
}
else
{
sensor.AddObservation(0.0f);
}
}
public override void OnActionReceived(float[] vectorAction)

{
m_Area.MatchReset();
}
transform.position = new Vector3(-m_InvertMult * Random.Range(6f, 8f), -1.5f, -1.8f) + transform.parent.transform.position;
transform.position = new Vector3(-m_InvertMult * 14f, 5f, -1.8f) + transform.parent.transform.position;
m_AgentRb.velocity = new Vector3(0f, 0f, 0f);
SetResetParameters();
}

8
Project/Assets/ML-Agents/Examples/Tennis/Scripts/TennisArea.cs


public void MatchReset()
{
var ballOut = Random.Range(6f, 8f);
var ballOut = 14f;
ball.transform.position = new Vector3(-ballOut, 6f, 0f) + transform.position;
ball.transform.position = new Vector3(-ballOut, 10f, 0f) + transform.position;
ball.transform.position = new Vector3(ballOut, 6f, 0f) + transform.position;
ball.transform.position = new Vector3(ballOut, 10f, 0f) + transform.position;
}
m_BallRb.velocity = new Vector3(0f, 0f, 0f);
ball.transform.localScale = new Vector3(.5f, .5f, .5f);

{
m_BallRb.AddForce(down);
var rgV = m_BallRb.velocity;
m_BallRb.velocity = new Vector3(Mathf.Clamp(rgV.x, -20f, 20f), Mathf.Clamp(rgV.y, -30f, 30f), rgV.z);
m_BallRb.velocity = new Vector3(Mathf.Clamp(rgV.x, -30f, 30f), Mathf.Clamp(rgV.y, -35f, 35f), rgV.z);
}
}
正在加载...
取消
保存