浏览代码

continuous move, disc comms

/soccer-comms/disc
Andrew Cohen 4 年前
当前提交
b7232ccc
共有 3 个文件被更改,包括 149 次插入73 次删除
  1. 32
      Project/Assets/ML-Agents/Examples/Soccer/Prefabs/SoccerFieldTwos.prefab
  2. 123
      Project/Assets/ML-Agents/Examples/Soccer/Scripts/AgentSoccer.cs
  3. 67
      Project/Assets/ML-Agents/Examples/Soccer/Scripts/AgentSoccerCollab.cs

32
Project/Assets/ML-Agents/Examples/Soccer/Prefabs/SoccerFieldTwos.prefab


VectorObservationSize: 10
NumStackedVectorObservations: 3
m_ActionSpec:
m_NumContinuousActions: 0
BranchSizes: 0300000003000000030000000a000000
VectorActionSize: 0300000003000000030000000a000000
m_NumContinuousActions: 3
BranchSizes: 0a000000
VectorActionSize:
m_Model: {fileID: 5022602860645237092, guid: fb0dcbf8aad8340428473b83fbb41557, type: 3}
m_Model: {fileID: 5022602860645237092, guid: 191c36f874b274185a637be2d959a324, type: 3}
m_InferenceDevice: 0
m_BehaviorType: 0
m_BehaviorName: SoccerTwos

VectorObservationSize: 10
NumStackedVectorObservations: 3
m_ActionSpec:
m_NumContinuousActions: 0
BranchSizes: 0300000003000000030000000a000000
VectorActionSize: 0300000003000000030000000a000000
m_NumContinuousActions: 3
BranchSizes: 0a000000
VectorActionSize:
m_Model: {fileID: 5022602860645237092, guid: fb0dcbf8aad8340428473b83fbb41557, type: 3}
m_Model: {fileID: 5022602860645237092, guid: 191c36f874b274185a637be2d959a324, type: 3}
m_InferenceDevice: 0
m_BehaviorType: 0
m_BehaviorName: SoccerTwos

VectorObservationSize: 10
NumStackedVectorObservations: 3
m_ActionSpec:
m_NumContinuousActions: 0
BranchSizes: 0300000003000000030000000a000000
VectorActionSize: 0300000003000000030000000a000000
m_NumContinuousActions: 3
BranchSizes: 0a000000
VectorActionSize:
m_Model: {fileID: 5022602860645237092, guid: fb0dcbf8aad8340428473b83fbb41557, type: 3}
m_Model: {fileID: 5022602860645237092, guid: 191c36f874b274185a637be2d959a324, type: 3}
m_InferenceDevice: 0
m_BehaviorType: 0
m_BehaviorName: SoccerTwos

VectorObservationSize: 10
NumStackedVectorObservations: 3
m_ActionSpec:
m_NumContinuousActions: 0
BranchSizes: 0300000003000000030000000a000000
VectorActionSize: 0300000003000000030000000a000000
m_NumContinuousActions: 3
BranchSizes: 0a000000
VectorActionSize:
m_Model: {fileID: 5022602860645237092, guid: fb0dcbf8aad8340428473b83fbb41557, type: 3}
m_Model: {fileID: 5022602860645237092, guid: 191c36f874b274185a637be2d959a324, type: 3}
m_InferenceDevice: 0
m_BehaviorType: 0
m_BehaviorName: SoccerTwos

123
Project/Assets/ML-Agents/Examples/Soccer/Scripts/AgentSoccer.cs


m_ResetParams = Academy.Instance.EnvironmentParameters;
}
public void MoveAgent(ActionSegment<int> act)
public void MoveAgent(ActionSegment<float> act)
{
var dirToGo = Vector3.zero;
var rotateDir = Vector3.zero;

var forwardAxis = act[0];
var rightAxis = act[1];
var rotateAxis = act[2];
switch (forwardAxis)
{
case 1:
dirToGo = transform.forward * m_ForwardSpeed;
m_KickPower = 1f;
break;
case 2:
dirToGo = transform.forward * -m_ForwardSpeed;
break;
}
var forward = Mathf.Clamp(act[0], -1f, 1f);
var right = Mathf.Clamp(act[1], -1f, 1f);
var rotate = Mathf.Clamp(act[2], -1f, 1f);
switch (rightAxis)
dirToGo = transform.forward * forward * m_ForwardSpeed;
dirToGo += transform.right * right * m_LateralSpeed;
rotateDir = -transform.up * rotate;
if (forward > 0)
case 1:
dirToGo = transform.right * m_LateralSpeed;
break;
case 2:
dirToGo = transform.right * -m_LateralSpeed;
break;
m_KickPower = forward;
switch (rotateAxis)
{
case 1:
rotateDir = transform.up * -1f;
break;
case 2:
rotateDir = transform.up * 1f;
break;
}
//m_KickPower = 0f;
//var forwardAxis = act[0];
//var rightAxis = act[1];
//var rotateAxis = act[2];
//switch (forwardAxis)
//{
// case 1:
// dirToGo = transform.forward * m_ForwardSpeed;
// m_KickPower = 1f;
// break;
// case 2:
// dirToGo = transform.forward * -m_ForwardSpeed;
// break;
//}
//switch (rightAxis)
//{
// case 1:
// dirToGo = transform.right * m_LateralSpeed;
// break;
// case 2:
// dirToGo = transform.right * -m_LateralSpeed;
// break;
//}
//switch (rotateAxis)
//{
// case 1:
// rotateDir = transform.up * -1f;
// break;
// case 2:
// rotateDir = transform.up * 1f;
// break;
//}
transform.Rotate(rotateDir, Time.deltaTime * 100f);
agentRb.AddForce(dirToGo * m_SoccerSettings.agentRunSpeed,

// Existential penalty cumulant for Generic
timePenalty -= m_Existential;
}
MoveAgent(actionBuffers.DiscreteActions);
//MoveAgent(actionBuffers.DiscreteActions);
MoveAgent(actionBuffers.ContinuousActions);
var discreteActionsOut = actionsOut.DiscreteActions;
discreteActionsOut.Clear();
var contOut = actionsOut.ContinuousActions;
contOut.Clear();
discreteActionsOut[0] = 1;
contOut[0] = 1f;
discreteActionsOut[0] = 2;
contOut[0] = -1f;
discreteActionsOut[2] = 1;
contOut[1] = -1f;
discreteActionsOut[2] = 2;
contOut[1] = 1f;
discreteActionsOut[1] = 1;
contOut[2] = 1f;
discreteActionsOut[1] = 2;
contOut[2] = -1f;
//var discreteActionsOut = actionsOut.DiscreteActions;
//discreteActionsOut.Clear();
////forward
//if (Input.GetKey(KeyCode.W))
//{
// discreteActionsOut[0] = 1;
//}
//if (Input.GetKey(KeyCode.S))
//{
// discreteActionsOut[0] = 2;
//}
////rotate
//if (Input.GetKey(KeyCode.A))
//{
// discreteActionsOut[2] = 1;
//}
//if (Input.GetKey(KeyCode.D))
//{
// discreteActionsOut[2] = 2;
//}
////right
//if (Input.GetKey(KeyCode.E))
//{
// discreteActionsOut[1] = 1;
//}
//if (Input.GetKey(KeyCode.Q))
//{
// discreteActionsOut[1] = 2;
//}
}
/// <summary>
/// Used to provide a "kick" to the ball.

67
Project/Assets/ML-Agents/Examples/Soccer/Scripts/AgentSoccerCollab.cs


base.OnActionReceived(actionBuffers);
//if (team == Team.Blue && tester == 1)
//{
// Debug.Log(actionBuffers.DiscreteActions[3]);
// Debug.Log(actionBuffers.DiscreteActions[0]);
teammate.tellAgent(actionBuffers.DiscreteActions[3]);
teammate.tellAgent(actionBuffers.DiscreteActions[0]);
}
public override void CollectObservations(VectorSensor sensor)

discreteActionsOut.Clear();
if (Input.GetKey(KeyCode.Alpha0))
{
discreteActionsOut[3] = 0;
discreteActionsOut[0] = 0;
discreteActionsOut[3] = 1;
discreteActionsOut[0] = 1;
discreteActionsOut[3] = 2;
discreteActionsOut[0] = 2;
discreteActionsOut[3] = 3;
discreteActionsOut[0] = 3;
discreteActionsOut[3] = 4;
discreteActionsOut[0] = 4;
discreteActionsOut[3] = 5;
discreteActionsOut[0] = 5;
discreteActionsOut[3] = 6;
discreteActionsOut[0] = 6;
discreteActionsOut[3] = 7;
discreteActionsOut[0] = 7;
discreteActionsOut[3] = 8;
discreteActionsOut[0] = 8;
discreteActionsOut[3] = 9;
discreteActionsOut[0] = 9;
var contOut = actionsOut.ContinuousActions;
contOut.Clear();
discreteActionsOut[0] = 1;
contOut[0] = 1f;
discreteActionsOut[0] = 2;
contOut[0] = -1f;
discreteActionsOut[2] = 1;
contOut[1] = -1f;
discreteActionsOut[2] = 2;
contOut[1] = 1f;
discreteActionsOut[1] = 1;
contOut[2] = 1f;
discreteActionsOut[1] = 2;
contOut[2] = -1f;
////forward
//if (Input.GetKey(KeyCode.W))
//{
// discreteActionsOut[0] = 1;
//}
//if (Input.GetKey(KeyCode.S))
//{
// discreteActionsOut[0] = 2;
//}
////rotate
//if (Input.GetKey(KeyCode.A))
//{
// discreteActionsOut[2] = 1;
//}
//if (Input.GetKey(KeyCode.D))
//{
// discreteActionsOut[2] = 2;
//}
////right
//if (Input.GetKey(KeyCode.E))
//{
// discreteActionsOut[1] = 1;
//}
//if (Input.GetKey(KeyCode.Q))
//{
// discreteActionsOut[1] = 2;
//}
}
}
正在加载...
取消
保存