浏览代码

refactor collab agent

/soccer-comms/disc
Andrew Cohen 4 年前
当前提交
f9062e02
共有 7 个文件被更改,包括 2072 次插入51 次删除
  1. 905
      Project/Assets/ML-Agents/Examples/Soccer/Prefabs/SoccerFieldTwos.prefab
  2. 49
      Project/Assets/ML-Agents/Examples/Soccer/Scenes/SoccerTwos.unity
  3. 19
      Project/Assets/ML-Agents/Examples/Soccer/Scripts/AgentSoccer.cs
  4. 125
      Project/Assets/ML-Agents/Examples/Soccer/Scripts/AgentSoccerCollab.cs
  5. 11
      Project/Assets/ML-Agents/Examples/Soccer/Scripts/AgentSoccerCollab.cs.meta
  6. 1001
      Project/Assets/ML-Agents/Examples/Soccer/TFModels/SoccerTwos-10999921.onnx
  7. 13
      Project/Assets/ML-Agents/Examples/Soccer/TFModels/SoccerTwos-10999921.onnx.meta

905
Project/Assets/ML-Agents/Examples/Soccer/Prefabs/SoccerFieldTwos.prefab
文件差异内容过多而无法显示
查看文件

49
Project/Assets/ML-Agents/Examples/Soccer/Scenes/SoccerTwos.unity


m_EnableBakedLightmaps: 1
m_EnableRealtimeLightmaps: 1
m_LightmapEditorSettings:
serializedVersion: 10
serializedVersion: 12
m_Resolution: 2
m_BakeResolution: 40
m_AtlasSize: 1024

m_CompAOExponentDirect: 0
m_ExtractAmbientOcclusion: 0
m_Padding: 2
m_LightmapParameters: {fileID: 0}
m_LightmapsBakeMode: 1

m_PVRDirectSampleCount: 32
m_PVRSampleCount: 500
m_PVRBounces: 2
m_PVREnvironmentSampleCount: 500
m_PVREnvironmentReferencePointCount: 2048
m_PVRFilteringMode: 2
m_PVRDenoiserTypeDirect: 0
m_PVRDenoiserTypeIndirect: 0
m_PVRDenoiserTypeAO: 0
m_PVRFilteringMode: 1
m_PVREnvironmentMIS: 0
m_PVRCulling: 1
m_PVRFilteringGaussRadiusDirect: 1
m_PVRFilteringGaussRadiusIndirect: 5

m_PVRFilteringAtrousPositionSigmaAO: 1
m_ShowResolutionOverlay: 1
m_ExportTrainingData: 0
m_TrainingDataDestination: TrainingData
m_LightingDataAsset: {fileID: 112000002, guid: 03723c7f910c3423aa1974f1b9ce8392,
type: 2}
m_UseShadowmask: 1

m_GameObject: {fileID: 255077123}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 1077351063, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Script: {fileID: 11500000, guid: 4f231c4fb786f3946a6b90b886c48677, type: 3}
m_Name:
m_EditorClassIdentifier:
m_HorizontalAxis: Horizontal

m_GameObject: {fileID: 255077123}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: -619905303, guid: f70555f144d8491a825f0804e09c671c, type: 3}
m_Script: {fileID: 11500000, guid: 76c392e42b5098c458856cdf6ecaaaa1, type: 3}
m_Name:
m_EditorClassIdentifier:
m_FirstSelected: {fileID: 0}

m_Modification:
m_TransformParent: {fileID: 0}
m_Modifications:
- target: {fileID: 1537641056927260, guid: 3ce107b4a79bc4eef83afde434932a68, type: 3}
propertyPath: m_IsActive
value: 0
objectReference: {fileID: 0}
- target: {fileID: 224194346362733190, guid: 3ce107b4a79bc4eef83afde434932a68,
type: 3}
propertyPath: m_LocalPosition.x

objectReference: {fileID: 0}
- target: {fileID: 1141134673700168, guid: 54f3340298537426e96a6cc530e2d5d8, type: 3}
propertyPath: m_IsActive
value: 1
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4558743310993102, guid: 54f3340298537426e96a6cc530e2d5d8, type: 3}
propertyPath: m_LocalPosition.x

propertyPath: m_RootOrder
value: 4
objectReference: {fileID: 0}
- target: {fileID: 4540201673231058, guid: 54f3340298537426e96a6cc530e2d5d8, type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 54f3340298537426e96a6cc530e2d5d8, type: 3}
--- !u!1 &1009000883

m_ClearFlags: 2
m_BackGroundColor: {r: 0.46666667, g: 0.5647059, b: 0.60784316, a: 1}
m_projectionMatrixMode: 1
m_GateFitMode: 2
m_FOVAxisMode: 0
m_GateFitMode: 2
m_FocalLength: 50
m_NormalizedViewPortRect:
serializedVersion: 2

objectReference: {fileID: 0}
- target: {fileID: 1141134673700168, guid: 54f3340298537426e96a6cc530e2d5d8, type: 3}
propertyPath: m_IsActive
value: 1
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4558743310993102, guid: 54f3340298537426e96a6cc530e2d5d8, type: 3}
propertyPath: m_LocalPosition.x

objectReference: {fileID: 0}
- target: {fileID: 1141134673700168, guid: 54f3340298537426e96a6cc530e2d5d8, type: 3}
propertyPath: m_IsActive
value: 1
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4558743310993102, guid: 54f3340298537426e96a6cc530e2d5d8, type: 3}
propertyPath: m_LocalPosition.x

objectReference: {fileID: 0}
- target: {fileID: 1141134673700168, guid: 54f3340298537426e96a6cc530e2d5d8, type: 3}
propertyPath: m_IsActive
value: 1
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4558743310993102, guid: 54f3340298537426e96a6cc530e2d5d8, type: 3}
propertyPath: m_LocalPosition.x

m_Name:
m_EditorClassIdentifier:
gravityMultiplier: 1
monitorVerticalOffset: 0
reuseCollisionCallbacks: 1
--- !u!114 &1574236051
MonoBehaviour:
m_ObjectHideFlags: 0

blueMaterial: {fileID: 2100000, guid: c9fa44c2c3f8ce74ca39a3355ea42631, type: 2}
randomizePlayersTeamForTraining: 0
agentRunSpeed: 2
strikerPunish: -0.1
strikerReward: 1
goaliePunish: -1
goalieReward: 0.1
--- !u!1001 &1606160104
PrefabInstance:
m_ObjectHideFlags: 0

objectReference: {fileID: 0}
- target: {fileID: 1141134673700168, guid: 54f3340298537426e96a6cc530e2d5d8, type: 3}
propertyPath: m_IsActive
value: 1
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4558743310993102, guid: 54f3340298537426e96a6cc530e2d5d8, type: 3}
propertyPath: m_LocalPosition.x

objectReference: {fileID: 0}
- target: {fileID: 1141134673700168, guid: 54f3340298537426e96a6cc530e2d5d8, type: 3}
propertyPath: m_IsActive
value: 1
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4558743310993102, guid: 54f3340298537426e96a6cc530e2d5d8, type: 3}
propertyPath: m_LocalPosition.x

objectReference: {fileID: 0}
- target: {fileID: 1141134673700168, guid: 54f3340298537426e96a6cc530e2d5d8, type: 3}
propertyPath: m_IsActive
value: 1
value: 0
objectReference: {fileID: 0}
- target: {fileID: 4558743310993102, guid: 54f3340298537426e96a6cc530e2d5d8, type: 3}
propertyPath: m_LocalPosition.x

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


public Team team;
float m_KickPower;
int m_PlayerIndex;
int m_Previous = 0;
public SoccerFieldArea area;
// The coefficient for the reward for colliding with a ball. Set using curriculum.

float m_Existential;
float m_LateralSpeed;
float m_ForwardSpeed;
float[] m_Message = new float[10];
public GameObject teammate_gb;
AgentSoccer teammate;
[HideInInspector]
public float timePenalty;

{
m_Existential = 1f / MaxStep;
m_BehaviorParameters = gameObject.GetComponent<BehaviorParameters>();
teammate = teammate_gb.GetComponent<AgentSoccer>();
if (m_BehaviorParameters.TeamId == (int)Team.Blue)
{
team = Team.Blue;

timePenalty -= m_Existential;
}
MoveAgent(actionBuffers.DiscreteActions);
teammate.tellAgent(actionBuffers.DiscreteActions[3]);
public override void CollectObservations(VectorSensor sensor)
{
sensor.AddObservation(m_Message);
}
public void tellAgent(int message)
{
m_Message[m_Previous] = 0f;
m_Message[message] = 1f;
m_Previous = message;
}
public override void Heuristic(in ActionBuffers actionsOut)
{

agentRb.velocity = Vector3.zero;
agentRb.angularVelocity = Vector3.zero;
SetResetParameters();
System.Array.Clear(m_Message, 0, m_Message.Length);
}
public void SetResetParameters()

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


using UnityEngine;
using Unity.MLAgents;
using Unity.MLAgents.Actuators;
using Unity.MLAgents.Policies;
using Unity.MLAgents.Sensors;
public class AgentSoccerCollab : AgentSoccer
{
public int tester = 0;
int m_Previous = 0;
float[] m_Message = new float[10];
public GameObject teammate_gb;
AgentSoccerCollab teammate;
public override void Initialize()
{
base.Initialize();
teammate = teammate_gb.GetComponent<AgentSoccerCollab>();
}
public override void OnActionReceived(ActionBuffers actionBuffers)
{
base.OnActionReceived(actionBuffers);
//if (team == Team.Blue && tester == 1)
//{
// Debug.Log(actionBuffers.DiscreteActions[3]);
//}
teammate.tellAgent(actionBuffers.DiscreteActions[3]);
}
public override void CollectObservations(VectorSensor sensor)
{
sensor.AddObservation(m_Message);
}
public void tellAgent(int message)
{
m_Message[m_Previous] = 0f;
m_Message[message] = 1f;
m_Previous = message;
}
public override void OnEpisodeBegin()
{
base.OnEpisodeBegin();
System.Array.Clear(m_Message, 0, m_Message.Length);
}
public override void Heuristic(in ActionBuffers actionsOut)
{
var discreteActionsOut = actionsOut.DiscreteActions;
discreteActionsOut.Clear();
if (Input.GetKey(KeyCode.Alpha0))
{
discreteActionsOut[3] = 0;
}
if (Input.GetKey(KeyCode.Alpha1))
{
discreteActionsOut[3] = 1;
}
if (Input.GetKey(KeyCode.Alpha2))
{
discreteActionsOut[3] = 2;
}
if (Input.GetKey(KeyCode.Alpha3))
{
discreteActionsOut[3] = 3;
}
if (Input.GetKey(KeyCode.Alpha4))
{
discreteActionsOut[3] = 4;
}
if (Input.GetKey(KeyCode.Alpha5))
{
discreteActionsOut[3] = 5;
}
if (Input.GetKey(KeyCode.Alpha6))
{
discreteActionsOut[3] = 6;
}
if (Input.GetKey(KeyCode.Alpha7))
{
discreteActionsOut[3] = 7;
}
if (Input.GetKey(KeyCode.Alpha8))
{
discreteActionsOut[3] = 8;
}
if (Input.GetKey(KeyCode.Alpha9))
{
discreteActionsOut[3] = 9;
}
//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;
}
}
}

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


fileFormatVersion: 2
guid: 506fb6eabb24441ffa15342d72f0bdd2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

1001
Project/Assets/ML-Agents/Examples/Soccer/TFModels/SoccerTwos-10999921.onnx
文件差异内容过多而无法显示
查看文件

13
Project/Assets/ML-Agents/Examples/Soccer/TFModels/SoccerTwos-10999921.onnx.meta


fileFormatVersion: 2
guid: fb0dcbf8aad8340428473b83fbb41557
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 11500000, guid: 683b6cb6d0a474744822c888b46772c9, type: 3}
optimizeModel: 1
forceArbitraryBatchSize: 1
treatErrorsAsWarnings: 0
正在加载...
取消
保存