Andrew Cohen
4 年前
当前提交
f9062e02
共有 7 个文件被更改,包括 2072 次插入 和 51 次删除
-
905Project/Assets/ML-Agents/Examples/Soccer/Prefabs/SoccerFieldTwos.prefab
-
49Project/Assets/ML-Agents/Examples/Soccer/Scenes/SoccerTwos.unity
-
19Project/Assets/ML-Agents/Examples/Soccer/Scripts/AgentSoccer.cs
-
125Project/Assets/ML-Agents/Examples/Soccer/Scripts/AgentSoccerCollab.cs
-
11Project/Assets/ML-Agents/Examples/Soccer/Scripts/AgentSoccerCollab.cs.meta
-
1001Project/Assets/ML-Agents/Examples/Soccer/TFModels/SoccerTwos-10999921.onnx
-
13Project/Assets/ML-Agents/Examples/Soccer/TFModels/SoccerTwos-10999921.onnx.meta
905
Project/Assets/ML-Agents/Examples/Soccer/Prefabs/SoccerFieldTwos.prefab
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
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; |
|||
} |
|||
} |
|||
} |
|
|||
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
文件差异内容过多而无法显示
查看文件
文件差异内容过多而无法显示
查看文件
|
|||
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 |
撰写
预览
正在加载...
取消
保存
Reference in new issue