浏览代码

Fixed all the // without a space after it

/develop-generalizationTraining-TrainerController
Vincent Gao 6 年前
当前提交
1c2c800a
共有 2 个文件被更改,包括 31 次插入31 次删除
  1. 10
      unity-environment/Assets/ML-Agents/Examples/3DBall/Scripts/Ball3DDecision.cs
  2. 52
      unity-environment/Assets/ML-Agents/Examples/Hallway/Scripts/HallwayAgent.cs

10
unity-environment/Assets/ML-Agents/Examples/3DBall/Scripts/Ball3DDecision.cs


if (gameObject.GetComponent<Brain>().brainParameters.vectorActionSpaceType == StateType.continuous)
{
List<float> act = new List<float>();
//state[5] is the velocity of the ball in the x orientation. We use this number to control the Platform's z axis rotation speed,
//so that the Platform is tilted in the x orientation correspondingly.
// state[5] is the velocity of the ball in the x orientation. We use this number to control the Platform's z axis rotation speed,
// so that the Platform is tilted in the x orientation correspondingly.
//state[7] is the velocity of the ball in the z orientation. We use this number to control the Platform's x axis rotation speed,
//so that the Platform is tilted in the z orientation correspondingly.
// state[7] is the velocity of the ball in the z orientation. We use this number to control the Platform's x axis rotation speed,
// so that the Platform is tilted in the z orientation correspondingly.
//If the vector action space type is discrete, then we don't do anything.
//If the vector action space type is discrete, then we don't do anything.
else
{
return new float[1]{ 1f };

52
unity-environment/Assets/ML-Agents/Examples/Hallway/Scripts/HallwayAgent.cs


//Put this script on your blue cube.
// Put this script on your blue cube.
using System.Collections;
using System.Collections.Generic;

{
public GameObject ground; //ground game object. we will use the area bounds to spawn the blocks
public GameObject ground; // ground game object. we will use the area bounds to spawn the blocks
public GameObject orangeBlock; //the orange block we are going to be pushing
public GameObject orangeBlock; // the orange block we are going to be pushing
Rigidbody shortBlockRB; //cached on initialization
Rigidbody agentRB; //cached on initialization
Material groundMaterial; //cached on Awake()
Rigidbody shortBlockRB; // cached on initialization
Rigidbody agentRB; // cached on initialization
Material groundMaterial; // cached on Awake()
Renderer groundRenderer;
HallwayAcademy academy;

{
base.InitializeAgent();
academy = FindObjectOfType<HallwayAcademy>();
brain = FindObjectOfType<Brain>(); //only one brain in the scene so this should find our brain. BRAAAINS.
brain = FindObjectOfType<Brain>(); // only one brain in the scene so this should find our brain. BRAAAINS.
agentRB = GetComponent<Rigidbody>(); //cache the agent rigidbody
groundRenderer = ground.GetComponent<Renderer>(); //get the ground renderer so we can change the material when a goal is scored
groundMaterial = groundRenderer.material; //starting material
agentRB = GetComponent<Rigidbody>(); // cache the agent rigidbody
groundRenderer = ground.GetComponent<Renderer>(); // get the ground renderer so we can change the material when a goal is scored
groundMaterial = groundRenderer.material; // starting material
}

RayPerception(rayDistance, rayAngles, detectableObjects, 0f);
}
//swap ground material, wait time seconds, then swap back to the regular ground material.
// swap ground material, wait time seconds, then swap back to the regular ground material.
yield return new WaitForSeconds(time); //wait for 2 sec
yield return new WaitForSeconds(time); // wait for 2 sec
groundRenderer.material = groundMaterial;
}

Vector3 dirToGo = Vector3.zero;
Vector3 rotateDir = Vector3.zero;
//If we're using Continuous control you will need to change the Action
// If we're using Continuous control you will need to change the Action
if (brain.brainParameters.vectorActionSpaceType == StateType.continuous)
{
dirToGo = transform.forward * Mathf.Clamp(act[0], -1f, 1f);

}
}
transform.Rotate(rotateDir, Time.deltaTime * 100f);
agentRB.AddForce(dirToGo * academy.agentRunSpeed, ForceMode.VelocityChange); //GO
agentRB.AddForce(dirToGo * academy.agentRunSpeed, ForceMode.VelocityChange); // GO
}
public override void AgentAction(float[] act)

MoveAgent(act); //perform agent actions
MoveAgent(act); // perform agent actions
if (!Physics.Raycast(agentRB.position, Vector3.down, 20)) //if the agent has gone over the edge, we done.
if (!Physics.Raycast(agentRB.position, Vector3.down, 20)) // if the agent has gone over the edge, we done.
fail = true; //fell off bro
fail = true; // fell off bro
Done(); //if we mark an agent as done it will be reset automatically. AgentReset() will be called.
Done(); // if we mark an agent as done it will be reset automatically. AgentReset() will be called.
StartCoroutine(GoalScoredSwapGroundMaterial(academy.failMaterial, .5f)); //swap ground material to indicate fail
StartCoroutine(GoalScoredSwapGroundMaterial(academy.failMaterial, .5f)); // swap ground material to indicate fail
}
}

if (col.gameObject.CompareTag("goal")) //touched goal
if (col.gameObject.CompareTag("goal")) // touched goal
AddReward(1f); //you get 5 points
StartCoroutine(GoalScoredSwapGroundMaterial(academy.goalScoredMaterial, 2)); //swap ground material for a bit to indicate we scored.
AddReward(1f); // you get 5 points
StartCoroutine(GoalScoredSwapGroundMaterial(academy.goalScoredMaterial, 2)); // swap ground material for a bit to indicate we scored.
AddReward(-0.1f); //you lose a point
StartCoroutine(GoalScoredSwapGroundMaterial(academy.failMaterial, .5f)); //swap ground material to indicate fail
AddReward(-0.1f); // you lose a point
StartCoroutine(GoalScoredSwapGroundMaterial(academy.failMaterial, .5f)); // swap ground material to indicate fail
Done(); //if we mark an agent as done it will be reset automatically. AgentReset() will be called.
Done(); // if we mark an agent as done it will be reset automatically. AgentReset() will be called.
//In the editor, if "Reset On Done" is checked then AgentReset() will be called automatically anytime we mark done = true in an agent script.
// In the editor, if "Reset On Done" is checked then AgentReset() will be called automatically anytime we mark done = true in an agent script.
public override void AgentReset()
{
selection = Random.Range(0, 2);

正在加载...
取消
保存