浏览代码

apply rider suggestions in Examples (#3846)

/release_1_branch
GitHub 5 年前
当前提交
3d15d51f
共有 23 个文件被更改,包括 35 次插入52 次删除
  1. 8
      Project/Assets/ML-Agents/Editor/Tests/StandaloneBuildTest.cs
  2. 1
      Project/Assets/ML-Agents/Examples/3DBall/Scripts/Ball3DAgent.cs
  3. 1
      Project/Assets/ML-Agents/Examples/3DBall/Scripts/Ball3DHardAgent.cs
  4. 20
      Project/Assets/ML-Agents/Examples/Basic/Scripts/BasicController.cs
  5. 3
      Project/Assets/ML-Agents/Examples/Basic/Scripts/BasicSensorComponent.cs
  6. 1
      Project/Assets/ML-Agents/Examples/Bouncer/Scripts/BouncerAgent.cs
  7. 1
      Project/Assets/ML-Agents/Examples/FoodCollector/Scripts/FoodCollectorAgent.cs
  8. 2
      Project/Assets/ML-Agents/Examples/FoodCollector/Scripts/FoodCollectorSettings.cs
  9. 10
      Project/Assets/ML-Agents/Examples/GridWorld/Scripts/GridAgent.cs
  10. 3
      Project/Assets/ML-Agents/Examples/GridWorld/Scripts/GridArea.cs
  11. 1
      Project/Assets/ML-Agents/Examples/GridWorld/Scripts/GridSettings.cs
  12. 5
      Project/Assets/ML-Agents/Examples/PushBlock/Scripts/PushAgentBasic.cs
  13. 3
      Project/Assets/ML-Agents/Examples/Reacher/Scripts/ReacherAgent.cs
  14. 8
      Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/ModelOverrider.cs
  15. 1
      Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/Monitor.cs
  16. 1
      Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/ProjectSettingsOverrides.cs
  17. 5
      Project/Assets/ML-Agents/Examples/Soccer/Scripts/AgentSoccer.cs
  18. 3
      Project/Assets/ML-Agents/Examples/Soccer/Scripts/SoccerFieldArea.cs
  19. 6
      Project/Assets/ML-Agents/Examples/Startup/Scripts/Startup.cs
  20. 1
      Project/Assets/ML-Agents/Examples/Tennis/Scripts/TennisAgent.cs
  21. 1
      Project/Assets/ML-Agents/Examples/Walker/Scripts/WalkerAgent.cs
  22. 1
      Project/Assets/ML-Agents/Examples/WallJump/Scripts/WallJumpAgent.cs
  23. 1
      Project/Assets/ML-Agents/Examples/Worm/Scripts/WormAgent.cs

8
Project/Assets/ML-Agents/Editor/Tests/StandaloneBuildTest.cs


{
public class StandaloneBuildTest
{
const string k_outputCommandLineFlag = "--mlagents-build-output-path";
const string k_sceneCommandLineFlag = "--mlagents-build-scene-path";
const string k_OutputCommandLineFlag = "--mlagents-build-output-path";
const string k_SceneCommandLineFlag = "--mlagents-build-scene-path";
public static void BuildStandalonePlayerOSX()
{

var args = Environment.GetCommandLineArgs();
for (var i = 0; i < args.Length - 1; i++)
{
if (args[i] == k_outputCommandLineFlag)
if (args[i] == k_OutputCommandLineFlag)
else if (args[i] == k_sceneCommandLineFlag)
else if (args[i] == k_SceneCommandLineFlag)
{
scenePath = args[i + 1];
}

1
Project/Assets/ML-Agents/Examples/3DBall/Scripts/Ball3DAgent.cs


using UnityEngine;
using Unity.MLAgents;
using Unity.MLAgents.Sensors;
using Unity.MLAgents.SideChannels;
public class Ball3DAgent : Agent
{

1
Project/Assets/ML-Agents/Examples/3DBall/Scripts/Ball3DHardAgent.cs


using UnityEngine;
using Unity.MLAgents;
using Unity.MLAgents.Sensors;
using Unity.MLAgents.SideChannels;
public class Ball3DHardAgent : Agent
{

20
Project/Assets/ML-Agents/Examples/Basic/Scripts/BasicController.cs


using UnityEngine;
using UnityEngine.SceneManagement;
using Unity.MLAgents;
using UnityEngine.Serialization;
/// <summary>
/// An example of how to use ML-Agents without inheriting from the Agent class.

{
public float timeBetweenDecisionsAtInference;
float m_TimeSinceDecision;
[FormerlySerializedAs("m_Position")]
public int m_Position;
public int position;
const int k_SmallGoalPosition = 7;
const int k_LargeGoalPosition = 17;
public GameObject largeGoal;

public void OnEnable()
{
m_Agent = GetComponent<Agent>();
m_Position = 10;
transform.position = new Vector3(m_Position - 10f, 0f, 0f);
position = 10;
transform.position = new Vector3(position - 10f, 0f, 0f);
smallGoal.transform.position = new Vector3(k_SmallGoalPosition - 10f, 0f, 0f);
largeGoal.transform.position = new Vector3(k_LargeGoalPosition - 10f, 0f, 0f);
}

break;
}
m_Position += direction;
if (m_Position < k_MinPosition) { m_Position = k_MinPosition; }
if (m_Position > k_MaxPosition) { m_Position = k_MaxPosition; }
position += direction;
if (position < k_MinPosition) { position = k_MinPosition; }
if (position > k_MaxPosition) { position = k_MaxPosition; }
gameObject.transform.position = new Vector3(m_Position - 10f, 0f, 0f);
gameObject.transform.position = new Vector3(position - 10f, 0f, 0f);
if (m_Position == k_SmallGoalPosition)
if (position == k_SmallGoalPosition)
{
m_Agent.AddReward(0.1f);
m_Agent.EndEpisode();

if (m_Position == k_LargeGoalPosition)
if (position == k_LargeGoalPosition)
{
m_Agent.AddReward(1f);
m_Agent.EndEpisode();

3
Project/Assets/ML-Agents/Examples/Basic/Scripts/BasicSensorComponent.cs


using System;
using Unity.MLAgents.Sensors;
using UnityEngine.Serialization;
namespace Unity.MLAgentsExamples
{

{
// One-hot encoding of the position
Array.Clear(output, 0, output.Length);
output[basicController.m_Position] = 1;
output[basicController.position] = 1;
}
/// <inheritdoc/>

1
Project/Assets/ML-Agents/Examples/Bouncer/Scripts/BouncerAgent.cs


using UnityEngine;
using Unity.MLAgents;
using Unity.MLAgents.Sensors;
using Unity.MLAgents.SideChannels;
public class BouncerAgent : Agent
{

1
Project/Assets/ML-Agents/Examples/FoodCollector/Scripts/FoodCollectorAgent.cs


using UnityEngine;
using Unity.MLAgents;
using Unity.MLAgents.Sensors;
using Unity.MLAgents.SideChannels;
public class FoodCollectorAgent : Agent
{

2
Project/Assets/ML-Agents/Examples/FoodCollector/Scripts/FoodCollectorSettings.cs


m_Recorder = Academy.Instance.StatsRecorder;
}
private void EnvironmentReset()
void EnvironmentReset()
{
ClearObjects(GameObject.FindGameObjectsWithTag("food"));
ClearObjects(GameObject.FindGameObjectsWithTag("badFood"));

10
Project/Assets/ML-Agents/Examples/GridWorld/Scripts/GridAgent.cs


using UnityEngine;
using System.Linq;
using Unity.MLAgents;
using Unity.MLAgents.Sensors;
using Unity.MLAgents.SideChannels;
public class GridAgent : Agent
{

if (positionX == 0)
{
actionMasker.SetMask(0, new int[]{ k_Left});
actionMasker.SetMask(0, new []{ k_Left});
actionMasker.SetMask(0, new int[]{k_Right});
actionMasker.SetMask(0, new []{k_Right});
actionMasker.SetMask(0, new int[]{k_Down});
actionMasker.SetMask(0, new []{k_Down});
actionMasker.SetMask(0, new int[]{k_Up});
actionMasker.SetMask(0, new []{k_Up});
}
}
}

3
Project/Assets/ML-Agents/Examples/GridWorld/Scripts/GridArea.cs


using UnityEngine;
using System.Linq;
using Unity.MLAgents;
using Unity.MLAgents.SideChannels;
public class GridArea : MonoBehaviour

m_InitialPosition = transform.position;
}
private void SetEnvironment()
void SetEnvironment()
{
transform.position = m_InitialPosition * (m_ResetParams.GetWithDefault("gridSize", 5f) + 1);
var playersList = new List<int>();

1
Project/Assets/ML-Agents/Examples/GridWorld/Scripts/GridSettings.cs


using UnityEngine;
using Unity.MLAgents;
using Unity.MLAgents.SideChannels;
public class GridSettings : MonoBehaviour
{

5
Project/Assets/ML-Agents/Examples/PushBlock/Scripts/PushAgentBasic.cs


using System.Collections;
using UnityEngine;
using Unity.MLAgents;
using Unity.MLAgents.SideChannels;
public class PushAgentBasic : Agent
{

/// </summary>
Renderer m_GroundRenderer;
private EnvironmentParameters m_ResetParams;
EnvironmentParameters m_ResetParams;
void Awake()
{

m_BlockRb.drag = m_ResetParams.GetWithDefault("block_drag", 0.5f);
}
private void SetResetParameters()
void SetResetParameters()
{
SetGroundMaterialFriction();
SetBlockProperties();

3
Project/Assets/ML-Agents/Examples/Reacher/Scripts/ReacherAgent.cs


using UnityEngine;
using Unity.MLAgents;
using Unity.MLAgents.Sensors;
using Unity.MLAgents.SideChannels;
public class ReacherAgent : Agent
{

// Frequency of the cosine deviation of the goal along the vertical dimension
float m_DeviationFreq;
private EnvironmentParameters m_ResetParams;
EnvironmentParameters m_ResetParams;
/// <summary>
/// Collect the rigidbodies of the reacher in order to resue them for

8
Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/ModelOverrider.cs


{
m_Agent.LazyInitialize();
var bp = m_Agent.GetComponent<BehaviorParameters>();
var name = bp.BehaviorName;
var behaviorName = bp.BehaviorName;
var nnModel = GetModelForBehaviorName(name);
Debug.Log($"Overriding behavior {name} for agent with model {nnModel?.name}");
var nnModel = GetModelForBehaviorName(behaviorName);
Debug.Log($"Overriding behavior {behaviorName} for agent with model {nnModel?.name}");
m_Agent.SetModel($"Override_{name}", nnModel);
m_Agent.SetModel($"Override_{behaviorName}", nnModel);
}
}

1
Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/Monitor.cs


s_TransformCamera = new Dictionary<Transform, Camera>();
}
/// <inheritdoc/>
void OnGUI()
{
if (!s_Initialized)

1
Project/Assets/ML-Agents/Examples/SharedAssets/Scripts/ProjectSettingsOverrides.cs


using UnityEngine;
using Unity.MLAgents;
using Unity.MLAgents.SideChannels;
namespace Unity.MLAgentsExamples
{

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


using UnityEngine;
using Unity.MLAgents;
using Unity.MLAgents.Policies;
using Unity.MLAgents.SideChannels;
public class AgentSoccer : Agent
{

float m_ForwardSpeed;
[HideInInspector]
public float timePenalty = 0;
public float timePenalty;
[HideInInspector]
public Rigidbody agentRb;

private EnvironmentParameters m_ResetParams;
EnvironmentParameters m_ResetParams;
public override void Initialize()
{

3
Project/Assets/ML-Agents/Examples/Soccer/Scripts/SoccerFieldArea.cs


using System.Collections;
using System.Collections.Generic;
using Unity.MLAgents;
using Unity.MLAgents.SideChannels;
using UnityEngine;
using UnityEngine.Serialization;

[HideInInspector]
public bool canResetBall;
private EnvironmentParameters m_ResetParams;
EnvironmentParameters m_ResetParams;
void Awake()
{

6
Project/Assets/ML-Agents/Examples/Startup/Scripts/Startup.cs


internal class Startup : MonoBehaviour
{
const string k_SceneVariableName = "SCENE_NAME";
private const string k_SceneCommandLineFlag = "--mlagents-scene-name";
const string k_SceneCommandLineFlag = "--mlagents-scene-name";
// Check for the CLI '--scene-name' flag. This will be used if
// no scene environment variable is found.
var args = Environment.GetCommandLineArgs();

{
sceneName = sceneEnvironmentVariable;
}
SwitchScene(sceneName);
}

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


using UnityEngine.UI;
using Unity.MLAgents;
using Unity.MLAgents.Sensors;
using Unity.MLAgents.SideChannels;
public class TennisAgent : Agent
{

1
Project/Assets/ML-Agents/Examples/Walker/Scripts/WalkerAgent.cs


using Unity.MLAgents;
using Unity.MLAgentsExamples;
using Unity.MLAgents.Sensors;
using Unity.MLAgents.SideChannels;
public class WalkerAgent : Agent
{

1
Project/Assets/ML-Agents/Examples/WallJump/Scripts/WallJumpAgent.cs


using Unity.MLAgents;
using Barracuda;
using Unity.MLAgents.Sensors;
using Unity.MLAgents.SideChannels;
public class WallJumpAgent : Agent
{

1
Project/Assets/ML-Agents/Examples/Worm/Scripts/WormAgent.cs


using System.Collections;
using UnityEngine;
using Unity.MLAgents;
using Unity.MLAgentsExamples;

正在加载...
取消
保存