浏览代码

Merge pull request #2280 from Unity-Technologies/develop-newResetParams-3DBall-Tennis-TwoSoccer

Develop new reset params 3 d ball tennis two soccer
/develop-generalizationTraining-TrainerController
GitHub 6 年前
当前提交
39e693b5
共有 15 个文件被更改,包括 176 次插入41 次删除
  1. 10
      UnitySDK/Assets/ML-Agents/Examples/3DBall/Scenes/3DBall.unity
  2. 10
      UnitySDK/Assets/ML-Agents/Examples/3DBall/Scenes/3DBallHard.unity
  3. 2
      UnitySDK/Assets/ML-Agents/Examples/3DBall/Scripts/Ball3DAcademy.cs
  4. 19
      UnitySDK/Assets/ML-Agents/Examples/3DBall/Scripts/Ball3DAgent.cs
  5. 19
      UnitySDK/Assets/ML-Agents/Examples/3DBall/Scripts/Ball3DHardAgent.cs
  6. 6
      UnitySDK/Assets/ML-Agents/Examples/Soccer/Scenes/SoccerTwos.unity
  7. 17
      UnitySDK/Assets/ML-Agents/Examples/Soccer/Scripts/AgentSoccer.cs
  8. 2
      UnitySDK/Assets/ML-Agents/Examples/Soccer/Scripts/SoccerAcademy.cs
  9. 25
      UnitySDK/Assets/ML-Agents/Examples/Soccer/Scripts/SoccerFieldArea.cs
  10. 8
      UnitySDK/Assets/ML-Agents/Examples/Tennis/Scenes/Tennis.unity
  11. 18
      UnitySDK/Assets/ML-Agents/Examples/Tennis/Scenes/TennisIL.unity
  12. 2
      UnitySDK/Assets/ML-Agents/Examples/Tennis/Scripts/HitWall.cs
  13. 1
      UnitySDK/Assets/ML-Agents/Examples/Tennis/Scripts/TennisAcademy.cs
  14. 40
      UnitySDK/Assets/ML-Agents/Examples/Tennis/Scripts/TennisAgent.cs
  15. 38
      docs/Learning-Environment-Examples.md

10
UnitySDK/Assets/ML-Agents/Examples/3DBall/Scenes/3DBall.unity


m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0.44824862, g: 0.49827534, b: 0.57558274, a: 1}
m_IndirectSpecularColor: {r: 0.44824898, g: 0.49827564, b: 0.5755826, a: 1}
--- !u!157 &3
LightmapSettings:
m_ObjectHideFlags: 0

timeScale: 1
targetFrameRate: -1
resetParameters:
resetParameters: []
resetParameters:
- key: mass
value: 1
- key: gravity
value: 9.81
- key: scale
value: 1
--- !u!1 &1746325439
GameObject:
m_ObjectHideFlags: 0

10
UnitySDK/Assets/ML-Agents/Examples/3DBall/Scenes/3DBallHard.unity


m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 0}
m_IndirectSpecularColor: {r: 0.45096254, g: 0.5008292, b: 0.5744089, a: 1}
m_IndirectSpecularColor: {r: 0.45096314, g: 0.50082976, b: 0.57440954, a: 1}
--- !u!157 &3
LightmapSettings:
m_ObjectHideFlags: 0

timeScale: 1
targetFrameRate: -1
resetParameters:
resetParameters: []
resetParameters:
- key: mass
value: 1
- key: gravity
value: 9.81
- key: scale
value: 1
--- !u!1001 &1591880668
Prefab:
m_ObjectHideFlags: 0

2
UnitySDK/Assets/ML-Agents/Examples/3DBall/Scripts/Ball3DAcademy.cs


{
public override void AcademyReset()
{
Physics.gravity = new Vector3(0, -resetParameters["gravity"], 0);
}
public override void AcademyStep()

19
UnitySDK/Assets/ML-Agents/Examples/3DBall/Scripts/Ball3DAgent.cs


[Header("Specific to Ball3D")]
public GameObject ball;
private Rigidbody ballRb;
private ResetParameters resetParams;
var academy = Object.FindObjectOfType<Academy>() as Academy;
resetParams = academy.resetParameters;
SetResetParameters();
}
public override void CollectObservations()

public override void AgentAction(float[] vectorAction, string textAction)
{
if (brain.brainParameters.vectorActionSpaceType == SpaceType.continuous)
{
var actionZ = 2f * Mathf.Clamp(vectorAction[0], -1f, 1f);

ballRb.velocity = new Vector3(0f, 0f, 0f);
ball.transform.position = new Vector3(Random.Range(-1.5f, 1.5f), 4f, Random.Range(-1.5f, 1.5f))
+ gameObject.transform.position;
//Reset the parameters when the Agent is reset.
SetResetParameters();
}
public void SetBall()
{
//Set the attributes of the ball by fetching the information from the academy
ballRb.mass = resetParams["mass"];
var scale = resetParams["scale"];
ball.transform.localScale = new Vector3(scale, scale, scale);
public void SetResetParameters()
{
SetBall();
}
}

19
UnitySDK/Assets/ML-Agents/Examples/3DBall/Scripts/Ball3DHardAgent.cs


[Header("Specific to Ball3DHard")]
public GameObject ball;
private Rigidbody ballRb;
private ResetParameters resetParams;
var academy = Object.FindObjectOfType<Academy>() as Academy;
resetParams = academy.resetParameters;
SetResetParameters();
}
public override void CollectObservations()

public override void AgentAction(float[] vectorAction, string textAction)
{
if (brain.brainParameters.vectorActionSpaceType == SpaceType.continuous)
{
var actionZ = 2f * Mathf.Clamp(vectorAction[0], -1f, 1f);

}
public void SetBall()
{
//Set the attributes of the ball by fetching the information from the academy
ballRb.mass = resetParams["mass"];
var scale = resetParams["scale"];
ball.transform.localScale = new Vector3(scale, scale, scale);
}
public void SetResetParameters()
{
SetBall();
}
}

6
UnitySDK/Assets/ML-Agents/Examples/Soccer/Scenes/SoccerTwos.unity


timeScale: 2
targetFrameRate: 60
resetParameters:
resetParameters: []
resetParameters:
- key: ball_scale
value: 7.5
- key: gravity
value: 9.81
brainStriker: {fileID: 11400000, guid: 29ed78b3e8fef4340b3a1f6954b88f18, type: 2}
brainGoalie: {fileID: 11400000, guid: 090fa5a8588f5433bb7f878e6f5ac954, type: 2}
redMaterial: {fileID: 2100000, guid: 776dd8b57653342839c3fb5f46ce664e, type: 2}

17
UnitySDK/Assets/ML-Agents/Examples/Soccer/Scripts/AgentSoccer.cs


public enum Team
{
Red,
Red,
Striker,
Striker,
[HideInInspector]
public Rigidbody agentRb;
SoccerAcademy academy;

var playerState = new PlayerState
{
agentRB = agentRb,
startingPos = transform.position,
agentRB = agentRb,
startingPos = transform.position,
agentScript = this,
};
area.playerStates.Add(playerState);

transform.position = area.GetRandomSpawnPos(agentRole, team);
agentRb.velocity = Vector3.zero;
agentRb.angularVelocity = Vector3.zero;
SetResetParameters();
}
public void SetResetParameters()
{
area.ResetBall();
}
}

2
UnitySDK/Assets/ML-Agents/Examples/Soccer/Scripts/SoccerAcademy.cs


}
public override void AcademyReset()
{
Physics.gravity = new Vector3(0, -resetParameters["gravity"], 0);
}
public override void AcademyStep()

25
UnitySDK/Assets/ML-Agents/Examples/Soccer/Scripts/SoccerFieldArea.cs


[System.Serializable]
public class PlayerState
{
public int playerIndex;
public Rigidbody agentRB;
public Vector3 startingPos;
public AgentSoccer agentScript;
public int playerIndex;
public Rigidbody agentRB;
public Vector3 startingPos;
public AgentSoccer agentScript;
public float ballPosReward;
}

public GameObject ball;
[HideInInspector]
public Rigidbody ballRB;
public GameObject ground;
public GameObject ground;
public GameObject centerPitch;
SoccerBallController ballController;
public List<PlayerState> playerStates = new List<PlayerState>();

public IEnumerator GoalScoredSwapGroundMaterial(Material mat, float time)
{
groundRenderer.material = mat;
yield return new WaitForSeconds(time);
yield return new WaitForSeconds(time);
groundRenderer.material = groundMaterial;
}

academy = FindObjectOfType<SoccerAcademy>();
groundRenderer = centerPitch.GetComponent<Renderer>();
groundRenderer = centerPitch.GetComponent<Renderer>();
groundMaterial = groundRenderer.material;
canResetBall = true;
if (goalTextUI) { goalTextUI.SetActive(false); }

{
xOffset = xOffset * -1f;
}
var randomSpawnPos = ground.transform.position +
new Vector3(xOffset, 0f, 0f)
var randomSpawnPos = ground.transform.position +
new Vector3(xOffset, 0f, 0f)
+ (Random.insideUnitSphere * 2);
randomSpawnPos.y = ground.transform.position.y + 2;
return randomSpawnPos;

{
var randomSpawnPos = ground.transform.position +
new Vector3(0f, 0f, 0f)
var randomSpawnPos = ground.transform.position +
new Vector3(0f, 0f, 0f)
+ (Random.insideUnitSphere * 2);
randomSpawnPos.y = ground.transform.position.y + 2;
return randomSpawnPos;

ball.transform.position = GetBallSpawnPosition();
ballRB.velocity = Vector3.zero;
ballRB.angularVelocity = Vector3.zero;
var ballScale = academy.resetParameters["ball_scale"];
ballRB.transform.localScale = new Vector3(ballScale, ballScale, ballScale);
}
}

8
UnitySDK/Assets/ML-Agents/Examples/Tennis/Scenes/Tennis.unity


timeScale: 1
targetFrameRate: 60
resetParameters:
resetParameters: []
resetParameters:
- key: gravity
value: 9.81
- key: angle
value: 55
- key: scale
value: 1
--- !u!1001 &1065879750
Prefab:
m_ObjectHideFlags: 0

18
UnitySDK/Assets/ML-Agents/Examples/Tennis/Scenes/TennisIL.unity


brain: {fileID: 11400000, guid: 6bf6a586a645b471bb9bd1194ae0e229, type: 2}
agentParameters:
agentCameras: []
agentRenderTextures: []
maxStep: 5000
resetOnDone: 1
onDemandDecision: 0

score: 0
scoreText: {fileID: 2073469450}
opponent: {fileID: 1894084401}
angle: 0
scale: 0
--- !u!65 &348265184
BoxCollider:
m_ObjectHideFlags: 0

timeScale: 1
targetFrameRate: 60
resetParameters:
resetParameters: []
resetParameters:
- key: angle
value: 55
- key: scale
value: 1
- key: gravity
value: 9.81
--- !u!1 &1114726487
GameObject:
m_ObjectHideFlags: 0

brain: {fileID: 11400000, guid: 1674996276be448c2ad51fb139e21e05, type: 2}
agentParameters:
agentCameras: []
agentRenderTextures: []
maxStep: 5000
resetOnDone: 1
onDemandDecision: 0

score: 0
scoreText: {fileID: 1871669621}
opponent: {fileID: 348265181}
angle: 0
scale: 0
--- !u!65 &1894084404
BoxCollider:
m_ObjectHideFlags: 0

2
UnitySDK/Assets/ML-Agents/Examples/Tennis/Scripts/HitWall.cs


lastAgentHit = collision.gameObject.name == "AgentA" ? 0 : 1;
}
}
}
}

1
UnitySDK/Assets/ML-Agents/Examples/Tennis/Scripts/TennisAcademy.cs


public override void AcademyReset()
{
Physics.gravity = new Vector3(0, -resetParameters["gravity"], 0);
}
public override void AcademyStep()

40
UnitySDK/Assets/ML-Agents/Examples/Tennis/Scripts/TennisAgent.cs


public bool invertX;
public int score;
public GameObject myArea;
public float angle;
public float scale;
private ResetParameters resetParams;
// Looks for the scoreboard based on the name of the gameObjects.
// Do not modify the names of the Score GameObjects

ballRb = ball.GetComponent<Rigidbody>();
var canvas = GameObject.Find(CanvasName);
GameObject scoreBoard;
var academy = Object.FindObjectOfType<Academy>() as Academy;
resetParams = academy.resetParameters;
if (invertX)
{
scoreBoard = canvas.transform.Find(ScoreBoardBName).gameObject;

scoreBoard = canvas.transform.Find(ScoreBoardAName).gameObject;
}
textComponent = scoreBoard.GetComponent<Text>();
SetResetParameters();
}
public override void CollectObservations()

{
var moveX = Mathf.Clamp(vectorAction[0], -1f, 1f) * invertMult;
var moveY = Mathf.Clamp(vectorAction[1], -1f, 1f);
if (moveY > 0.5 && transform.position.y - transform.parent.transform.position.y < -1.5f)
{
agentRb.velocity = new Vector3(agentRb.velocity.x, 7f, 0f);

if (invertX && transform.position.x - transform.parent.transform.position.x < -invertMult ||
if (invertX && transform.position.x - transform.parent.transform.position.x < -invertMult ||
transform.position = new Vector3(-invertMult + transform.parent.transform.position.x,
transform.position.y,
transform.position.z);
transform.position = new Vector3(-invertMult + transform.parent.transform.position.x,
transform.position.y,
transform.position.z);
}
textComponent.text = score.ToString();

transform.position = new Vector3(-invertMult * Random.Range(6f, 8f), -1.5f, 0f) + transform.parent.transform.position;
agentRb.velocity = new Vector3(0f, 0f, 0f);
SetResetParameters();
}
public void SetRacket()
{
angle = resetParams["angle"];
gameObject.transform.eulerAngles = new Vector3(
gameObject.transform.eulerAngles.x,
gameObject.transform.eulerAngles.y,
invertMult * angle
);
}
public void SetBall()
{
scale = resetParams["scale"];
ball.transform.localScale = new Vector3(scale, scale, scale);
}
public void SetResetParameters()
{
SetRacket();
SetBall();
}
}

38
docs/Learning-Environment-Examples.md


* Vector Action space: (Continuous) Size of 2, with one value corresponding to
X-rotation, and the other to Z-rotation.
* Visual Observations: None.
* Reset Parameters: None
* Reset Parameters: Three, corresponding to the following:
* scale: Specifies the scale of the ball in the 3 dimensions (equal across the three dimensions)
* Default: 1
* Recommended Minimum: 0.2
* Recommended Maximum: 5
* gravity: Magnitude of gravity
* Default: 9.81
* Recommended Minimum: 4
* Recommended Maximum: 105
* mass: Specifies mass of the ball
* Default: 1
* Recommended Minimum: 0.1
* Recommended Maximum: 20
* Benchmark Mean Reward: 100
## [GridWorld](https://youtu.be/gu8HE9WKEVI)

* Vector Action space: (Continuous) Size of 2, corresponding to movement
toward net or away from net, and jumping.
* Visual Observations: None.
* Reset Parameters: One, corresponding to size of ball.
* Reset Parameters: Three, corresponding to the following:
* angle: Angle of the racket from the vertical (Y) axis.
* Default: 55
* Recommended Minimum: 35
* Recommended Maximum: 65
* gravity: Magnitude of gravity
* Default: 9.81
* Recommended Minimum: 6
* Recommended Maximum: 20
* scale: Specifies the scale of the ball in the 3 dimensions (equal across the three dimensions)
* Default: 1
* Recommended Minimum: 0.2
* Recommended Maximum: 5
* Benchmark Mean Reward: 2.5
* Optional Imitation Learning scene: `TennisIL`.

as well as rotation.
* Goalie: 4 actions corresponding to forward, backward, sideways movement.
* Visual Observations: None.
* Reset Parameters: None
* Reset Parameters: Two, corresponding to the following:
* ball_scale: Specifies the scale of the ball in the 3 dimensions (equal across the three dimensions)
* Default: 7.5
* Recommended minimum: 4
* Recommended maximum: 10
* gravity: Magnitude of the gravity
* Default: 9.81
* Recommended minimum: 6
* Recommended maximum: 20
* Benchmark Mean Reward (Striker & Goalie Brain): 0 (the means will be inverse
of each other and criss crosses during training) __Note that our trainer is currently unable to consistently train this environment__

正在加载...
取消
保存