浏览代码

added bounce obs to agent/more downward force on ball

/asymm-envs
Andrew Cohen 5 年前
当前提交
e5b883db
共有 4 个文件被更改,包括 24 次插入19 次删除
  1. 11
      Project/Assets/ML-Agents/Examples/Tennis/Prefabs/TennisArea.prefab
  2. 21
      Project/Assets/ML-Agents/Examples/Tennis/Scripts/HitWall.cs
  3. 4
      Project/Assets/ML-Agents/Examples/Tennis/Scripts/TennisAgent.cs
  4. 7
      Project/Assets/ML-Agents/Examples/Tennis/Scripts/TennisArea.cs

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


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

m_EditorClassIdentifier:
DecisionPeriod: 5
TakeActionsBetweenDecisions: 1
offsetStep: 0
--- !u!1 &1194790474478638
GameObject:
m_ObjectHideFlags: 0

m_Name:
m_EditorClassIdentifier:
areaObject: {fileID: 1541947554534326}
lastFloorHit: 0
--- !u!1 &1299636753784036
GameObject:
m_ObjectHideFlags: 0

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

m_EditorClassIdentifier:
DecisionPeriod: 5
TakeActionsBetweenDecisions: 1
offsetStep: 0
--- !u!1 &1969551055586186
GameObject:
m_ObjectHideFlags: 0

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


FloorBHit
}
FloorHit m_LastFloorHit;
[HideInInspector]
public FloorHit lastFloorHit;
TennisArea m_Area;
TennisAgent m_AgentA;

public void ResetPoint()
{
m_LastFloorHit = FloorHit.Service;
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 || m_LastFloorHit == FloorHit.FloorAHit)
if (m_LastAgentHit == 0 || 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 || m_LastFloorHit == FloorHit.FloorBHit)
if (m_LastAgentHit == 1 || lastFloorHit == FloorHit.FloorBHit)
{
AgentAWins();
}

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

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

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

4
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);
sensor.AddObservation(System.Convert.ToInt32(m_BallScript.lastFloorHit == HitWall.FloorHit.FloorHitUnset));
}
public override void OnActionReceived(float[] vectorAction)

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


public GameObject agentB;
Rigidbody m_BallRb;
HitWall m_BallScript;
Vector3 down = new Vector3(0f, -15f, 0f);
Vector3 down = new Vector3(0f, -45f, 0f);
// Use this for initialization
void Start()

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