浏览代码

fixed actions

/develop/cubewars/splashdamage
Andrew Cohen 4 年前
当前提交
2643fcd5
共有 11 个文件被更改,包括 148 次插入202 次删除
  1. 2
      Project/Assets/ML-Agents/Examples/CubeWars/Materials/dragonfire.mat
  2. 2
      Project/Assets/ML-Agents/Examples/CubeWars/Materials/dragonscales.mat
  3. 2
      Project/Assets/ML-Agents/Examples/CubeWars/Materials/dragonskin.mat
  4. 82
      Project/Assets/ML-Agents/Examples/CubeWars/Prefabs/CubeWarArea.prefab
  5. 27
      Project/Assets/ML-Agents/Examples/CubeWars/Prefabs/SmallAgent.prefab
  6. 2
      Project/Assets/ML-Agents/Examples/CubeWars/Scripts/CubeWarArea.cs
  7. 5
      Project/Assets/ML-Agents/Examples/CubeWars/Scripts/CubeWarSettings.cs
  8. 108
      Project/Assets/ML-Agents/Examples/CubeWars/Scripts/LargeCubeAgent.cs
  9. 107
      Project/Assets/ML-Agents/Examples/CubeWars/Scripts/SmallCubeAgent.cs
  10. 5
      Project/Assets/ML-Agents/Examples/CubeWars/TFModels/SmallCubeSoldier.nn.meta
  11. 8
      Project/Assets/ML-Agents/Examples/CubeWars.meta

2
Project/Assets/ML-Agents/Examples/CubeWars/Materials/dragonfire.mat


m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: godzillafire
m_Name: dragonfire
m_Shader: {fileID: 211, guid: 0000000000000000f000000000000000, type: 0}
m_ShaderKeywords: EFFECT_BUMP _ALPHABLEND_ON _EMISSION _SMOOTHNESS_TEXTURE_ALBEDO_CHANNEL_A
m_LightmapFlags: 0

2
Project/Assets/ML-Agents/Examples/CubeWars/Materials/dragonscales.mat


m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: GodzillaScales
m_Name: dragonscales
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
m_ShaderKeywords:
m_LightmapFlags: 4

2
Project/Assets/ML-Agents/Examples/CubeWars/Materials/dragonskin.mat


m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Godzilla
m_Name: dragonskin
m_Shader: {fileID: 46, guid: 0000000000000000f000000000000000, type: 0}
m_ShaderKeywords:
m_LightmapFlags: 4

82
Project/Assets/ML-Agents/Examples/CubeWars/Prefabs/CubeWarArea.prefab


m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0

m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0

m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0

m_Name:
m_EditorClassIdentifier:
m_BrainParameters:
vectorObservationSize: 3
numStackedVectorObservations: 1
vectorActionSize: 0300000003000000030000000200000002000000
vectorActionDescriptions: []
vectorActionSpaceType: 0
VectorObservationSize: 3
NumStackedVectorObservations: 1
m_ActionSpec:
m_NumContinuousActions: 3
BranchSizes: 0200000002000000
VectorActionSize:
VectorActionDescriptions: []
VectorActionSpaceType: 0
hasUpgradedBrainParametersWithActionSpec: 1
m_Model: {fileID: 11400000, guid: fa881d0c4f6b44ea9880a781d0771fc9, type: 3}
m_InferenceDevice: 0
m_BehaviorType: 0

m_UseChildActuators: 1
m_ObservableAttributeHandling: 0
--- !u!114 &4533210983478432918
MonoBehaviour:
m_ObjectHideFlags: 0

m_EditorClassIdentifier:
DecisionPeriod: 5
TakeActionsBetweenDecisions: 1
offsetStep: 0
--- !u!114 &690297395971514217
MonoBehaviour:
m_ObjectHideFlags: 0

agentParameters:
maxStep: 0
hasUpgradedFromAgentParameters: 1
maxStep: 3000
MaxStep: 3000
area: {fileID: 1819751139121548}
turnSpeed: 150
moveSpeed: 1

m_Modification:
m_TransformParent: {fileID: 4688212428263696}
m_Modifications:
- target: {fileID: 5940168890073970201, guid: 4dd35c7381e7445c99133a34a83e21db,
type: 3}
propertyPath: area
value:
objectReference: {fileID: 1819751139121548}
- target: {fileID: 5940168890073970201, guid: 4dd35c7381e7445c99133a34a83e21db,
type: 3}
propertyPath: largeAgent
value:
objectReference: {fileID: 5707177387575911509}
- target: {fileID: 8081094897351109481, guid: 4dd35c7381e7445c99133a34a83e21db,
type: 3}
propertyPath: m_LocalPosition.x

propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5940168890073970201, guid: 4dd35c7381e7445c99133a34a83e21db,
type: 3}
propertyPath: area
value:
objectReference: {fileID: 1819751139121548}
- target: {fileID: 5940168890073970201, guid: 4dd35c7381e7445c99133a34a83e21db,
type: 3}
propertyPath: largeAgent
value:
objectReference: {fileID: 5707177387575911509}
- target: {fileID: 8083776131842293165, guid: 4dd35c7381e7445c99133a34a83e21db,
type: 3}
propertyPath: m_Name

m_Modification:
m_TransformParent: {fileID: 4688212428263696}
m_Modifications:
- target: {fileID: 5940168890073970201, guid: 4dd35c7381e7445c99133a34a83e21db,
type: 3}
propertyPath: largeAgent
value:
objectReference: {fileID: 5707177387575911509}
- target: {fileID: 5940168890073970201, guid: 4dd35c7381e7445c99133a34a83e21db,
type: 3}
propertyPath: area
value:
objectReference: {fileID: 1819751139121548}
- target: {fileID: 8081094897351109481, guid: 4dd35c7381e7445c99133a34a83e21db,
type: 3}
propertyPath: m_LocalPosition.x

propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5940168890073970201, guid: 4dd35c7381e7445c99133a34a83e21db,
type: 3}
propertyPath: largeAgent
value:
objectReference: {fileID: 5707177387575911509}
- target: {fileID: 5940168890073970201, guid: 4dd35c7381e7445c99133a34a83e21db,
type: 3}
propertyPath: area
value:
objectReference: {fileID: 1819751139121548}
- target: {fileID: 8083776131842293165, guid: 4dd35c7381e7445c99133a34a83e21db,
type: 3}
propertyPath: m_Name

m_Modification:
m_TransformParent: {fileID: 4688212428263696}
m_Modifications:
- target: {fileID: 5940168890073970201, guid: 4dd35c7381e7445c99133a34a83e21db,
type: 3}
propertyPath: area
value:
objectReference: {fileID: 1819751139121548}
- target: {fileID: 5940168890073970201, guid: 4dd35c7381e7445c99133a34a83e21db,
type: 3}
propertyPath: largeAgent
value:
objectReference: {fileID: 5707177387575911509}
- target: {fileID: 8081094897351109481, guid: 4dd35c7381e7445c99133a34a83e21db,
type: 3}
propertyPath: m_LocalPosition.x

propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 5940168890073970201, guid: 4dd35c7381e7445c99133a34a83e21db,
type: 3}
propertyPath: area
value:
objectReference: {fileID: 1819751139121548}
- target: {fileID: 5940168890073970201, guid: 4dd35c7381e7445c99133a34a83e21db,
type: 3}
propertyPath: largeAgent
value:
objectReference: {fileID: 5707177387575911509}
- target: {fileID: 8083776131842293165, guid: 4dd35c7381e7445c99133a34a83e21db,
type: 3}
propertyPath: m_Name

27
Project/Assets/ML-Agents/Examples/CubeWars/Prefabs/SmallAgent.prefab


m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0

m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0

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

m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0

m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0

m_Name:
m_EditorClassIdentifier:
m_BrainParameters:
vectorObservationSize: 4
numStackedVectorObservations: 2
vectorActionSize: 03000000030000000300000002000000
vectorActionDescriptions: []
vectorActionSpaceType: 0
VectorObservationSize: 4
NumStackedVectorObservations: 2
m_ActionSpec:
m_NumContinuousActions: 3
BranchSizes: 02000000
VectorActionSize:
VectorActionDescriptions: []
VectorActionSpaceType: 0
hasUpgradedBrainParametersWithActionSpec: 1
m_Model: {fileID: 11400000, guid: 697e3166f993b4e4cb890de8be9ec842, type: 3}
m_InferenceDevice: 0
m_BehaviorType: 0

m_UseChildActuators: 1
m_ObservableAttributeHandling: 0
--- !u!114 &8195976838962489967
MonoBehaviour:
m_ObjectHideFlags: 0

m_EditorClassIdentifier:
DecisionPeriod: 5
TakeActionsBetweenDecisions: 1
offsetStep: 0
--- !u!114 &5940168890073970201
MonoBehaviour:
m_ObjectHideFlags: 0

agentParameters:
maxStep: 0
hasUpgradedFromAgentParameters: 1
maxStep: 3000
MaxStep: 3000
area: {fileID: 0}
largeAgent: {fileID: 0}
turnSpeed: 300

m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 1
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0

2
Project/Assets/ML-Agents/Examples/CubeWars/Scripts/CubeWarArea.cs


using UnityEngine;
using MLAgentsExamples;
using Unity.MLAgentsExamples;
public class CubeWarArea : Area
{

5
Project/Assets/ML-Agents/Examples/CubeWars/Scripts/CubeWarSettings.cs


using System;
using UnityEngine;
using UnityEngine.UI;
using MLAgents;
using MLAgents.SideChannels;
using Unity.MLAgents;
public class CubeWarSettings : MonoBehaviour
{

public int totalScore;
public Text scoreText;
StatsSideChannel m_statsSideChannel;
// public void Awake()
// {

108
Project/Assets/ML-Agents/Examples/CubeWars/Scripts/LargeCubeAgent.cs


using UnityEngine;
using MLAgents;
using MLAgents.Sensors;
using Unity.MLAgents;
using Unity.MLAgents.Actuators;
using Unity.MLAgents.Sensors;
public class LargeCubeAgent : Agent
{

bool m_Shockwave;
float m_ShockwaveTime;
Rigidbody m_AgentRb;
float m_LaserLength;
// float m_LaserLength;
float m_HitPoints;
// Speed of agent rotation.
public float turnSpeed;

return new Color32(r, g, b, 255);
}
public void MoveAgent(float[] act)
public void MoveAgent(ActionBuffers actionBuffers)
{
m_Shoot = false;
m_Shockwave = false;

var continuousActions = actionBuffers.ContinuousActions;
var discreteActions = actionBuffers.DiscreteActions;
var shootCommand = false;
var shockwaveCommand = false;
var forwardAxis = (int)act[0];
var rightAxis = (int)act[1];
var rotateAxis = (int)act[2];
var shootAxis = (int)act[3];
var shockwaveAxis = (int)act[4];
var forward = Mathf.Clamp(continuousActions[0], -1f, 1f);
var right = Mathf.Clamp(continuousActions[1], -1f, 1f);
var rotate = Mathf.Clamp(continuousActions[2], -1f, 1f);
switch (forwardAxis)
{
case 1:
dirToGo = transform.forward;
break;
case 2:
dirToGo = -transform.forward;
break;
}
dirToGo = transform.forward * forward;
dirToGo += transform.right * right;
rotateDir = -transform.up * rotate;
switch (rightAxis)
{
case 1:
dirToGo = transform.right;
break;
case 2:
dirToGo = -transform.right;
break;
}
var shootCommand = (int)discreteActions[0] > 0;
var shockwaveCommand = (int)discreteActions[1] > 0;
switch (rotateAxis)
{
case 1:
rotateDir = -transform.up;
break;
case 2:
rotateDir = transform.up;
break;
}
switch (shootAxis)
{
case 1:
shootCommand = true;
break;
}
switch (shockwaveAxis)
{
case 1:
shockwaveCommand = true;
break;
}
if (shootCommand)
{
if (Time.time > m_ShootTime + 1f)

}
}
public override void OnActionReceived(float[] vectorAction)
public override void OnActionReceived(ActionBuffers actionBuffers)
MoveAgent(vectorAction);
MoveAgent(actionBuffers);
public override float[] Heuristic()
public override void Heuristic(in ActionBuffers actionsOut)
var action = new float[5];
var continuousActionsOut = actionsOut.ContinuousActions;
continuousActionsOut[0] = 0;
continuousActionsOut[1] = 0;
continuousActionsOut[2] = 0;
action[2] = 2f;
continuousActionsOut[2] = 1;
action[0] = 1f;
}
if (Input.GetKey(KeyCode.E))
{
action[1] = 1f;
}
if (Input.GetKey(KeyCode.Q))
{
action[1] = 2f;
continuousActionsOut[0] = 1;
action[2] = 1f;
continuousActionsOut[2] = -1;
action[0] = 2f;
continuousActionsOut[0] = -1;
action[3] = Input.GetKey(KeyCode.Space) ? 1.0f : 0.0f;
action[4] = Input.GetKey(KeyCode.O) ? 1.0f : 0.0f;
return action;
var discreteActionsOut = actionsOut.DiscreteActions;
discreteActionsOut[0] = Input.GetKey(KeyCode.Space) ? 1 : 0;
discreteActionsOut[1] = Input.GetKey(KeyCode.O) ? 1 : 0;
}
public override void OnEpisodeBegin()

return m_Dead;
}
public void SetLaserLengths()
{
m_LaserLength = 1f;
}
//public void SetLaserLengths()
//{
// m_LaserLength = 1f;
//}
public void SetAgentScale()
{

public void SetResetParameters()
{
SetLaserLengths();
// SetLaserLengths();
SetAgentScale();
}
}

107
Project/Assets/ML-Agents/Examples/CubeWars/Scripts/SmallCubeAgent.cs


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

bool m_Shoot;
float m_ShootTime;
Rigidbody m_AgentRb;
float m_LaserLength;
//float m_LaserLength;
float m_HitPoints;
// Speed of agent rotation.
public float turnSpeed;

return new Color32(r, g, b, 255);
}
public void MoveAgent(float[] act)
public void MoveAgent(ActionBuffers actionBuffers)
var continuousActions = actionBuffers.ContinuousActions;
var discreteActions = actionBuffers.DiscreteActions;
var shootCommand = false;
var forwardAxis = (int)act[0];
var rightAxis = (int)act[1];
var rotateAxis = (int)act[2];
var shootAxis = (int)act[3];
var forward = Mathf.Clamp(continuousActions[0], -1f, 1f);
var right = Mathf.Clamp(continuousActions[1], -1f, 1f);
var rotate = Mathf.Clamp(continuousActions[2], -1f, 1f);
switch (forwardAxis)
{
case 1:
dirToGo = transform.forward;
break;
case 2:
dirToGo = -transform.forward;
break;
}
dirToGo = transform.forward * forward;
dirToGo += transform.right * right;
rotateDir = -transform.up * rotate;
switch (rightAxis)
{
case 1:
dirToGo = transform.right;
break;
case 2:
dirToGo = -transform.right;
break;
}
var shootCommand = (int)discreteActions[0] > 0;
switch (rotateAxis)
{
case 1:
rotateDir = -transform.up;
break;
case 2:
rotateDir = transform.up;
break;
}
switch (shootAxis)
{
case 1:
shootCommand = true;
break;
}
if (shootCommand)
{
if (Time.time > m_ShootTime + .4f)

transform.Rotate(rotateDir, Time.fixedDeltaTime * turnSpeed);
m_AgentRb.AddForce(dirToGo * moveSpeed, ForceMode.VelocityChange);
}
//if (m_AgentRb.velocity.sqrMagnitude > 25f) // slow it down
//{
// m_AgentRb.velocity *= 0.95f;
//}
if (m_Shoot)
{

}
}
public override void OnActionReceived(float[] vectorAction)
public override void OnActionReceived(ActionBuffers actionBuffers)
MoveAgent(vectorAction);
MoveAgent(actionBuffers);
public override float[] Heuristic()
public override void Heuristic(in ActionBuffers actionsOut)
var action = new float[4];
var continuousActionsOut = actionsOut.ContinuousActions;
continuousActionsOut[0] = 0;
continuousActionsOut[1] = 0;
continuousActionsOut[2] = 0;
action[2] = 2f;
continuousActionsOut[2] = 1;
action[0] = 1f;
}
if (Input.GetKey(KeyCode.E))
{
action[1] = 1f;
}
if (Input.GetKey(KeyCode.Q))
{
action[1] = 2f;
continuousActionsOut[0] = 1;
action[2] = 1f;
continuousActionsOut[2] = -1;
action[0] = 2f;
continuousActionsOut[0] = -1;
action[3] = Input.GetKey(KeyCode.Space) ? 1.0f : 0.0f;
return action;
var discreteActionsOut = actionsOut.DiscreteActions;
discreteActionsOut[0] = Input.GetKey(KeyCode.Space) ? 1 : 0;
}
public override void OnEpisodeBegin()

m_Shoot = false;
m_ShootTime = -.5f;
//m_Bonus = Academy.Instance.FloatProperties.GetPropertyWithDefault("bonus", 0);
m_Bonus = SideChannelUtils.GetSideChannel<FloatPropertiesChannel>().GetPropertyWithDefault("bonus", 0);
m_Bonus = .2f;//SideChannelUtils.GetSideChannel<FloatPropertiesChannel>().GetPropertyWithDefault("bonus", 0);
m_AgentRb.velocity = Vector3.zero;
float smallRange = 50f * m_MyArea.range;

return m_Dead;
}
public void SetLaserLengths()
{
m_LaserLength = 1f;
}
//public void SetLaserLengths()
//{
// m_LaserLength = 1f;
//}
public void SetAgentScale()
{

public void SetResetParameters()
{
SetLaserLengths();
//SetLaserLengths();
SetAgentScale();
}
}

5
Project/Assets/ML-Agents/Examples/CubeWars/TFModels/SmallCubeSoldier.nn.meta


fileFormatVersion: 2
guid: 697e3166f993b4e4cb890de8be9ec842
ScriptedImporter:
fileIDToRecycleName:
11400000: main obj
11400002: model data
internalIDToNameTable: []
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:

8
Project/Assets/ML-Agents/Examples/CubeWars.meta


fileFormatVersion: 2
guid: 624ff327b14154c41869c6ecdcdcc167
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存