浏览代码

-

/bullet-hell-barracuda-test-1.3.1
vincentpierre 4 年前
当前提交
8dd003e6
共有 10 个文件被更改,包括 482 次插入583 次删除
  1. 846
      Project/Assets/ML-Agents/Examples/Arena-Sequence/Prefabs/Area.prefab
  2. 40
      Project/Assets/ML-Agents/Examples/Arena-Sequence/Scenes/ArenaLearnSequence.unity
  3. 2
      Project/Assets/ML-Agents/Examples/Arena-Sequence/Scripts/SequenceTile.cs
  4. 133
      Project/Assets/ML-Agents/Examples/Arena-Sequence/Scripts/SequencerAgent.cs
  5. 2
      Project/ProjectSettings/ProjectVersion.txt
  6. 2
      com.unity.ml-agents/Runtime/Sensors/BufferSensor.cs
  7. 2
      com.unity.ml-agents/Runtime/Sensors/BufferSensorComponent.cs
  8. 2
      com.unity.ml-agents/Runtime/Sensors/IDimensionPropertiesSensor.cs
  9. 28
      config/ppo/Sorter.yaml
  10. 8
      Project/Assets/ML-Agents/Examples/Arena-Sequence/TFModels.meta

846
Project/Assets/ML-Agents/Examples/Arena-Sequence/Prefabs/Area.prefab
文件差异内容过多而无法显示
查看文件

40
Project/Assets/ML-Agents/Examples/Arena-Sequence/Scenes/ArenaLearnSequence.unity


objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 3ce107b4a79bc4eef83afde434932a68, type: 3}
--- !u!1001 &3646228403529383018
--- !u!1001 &8757788144016958866
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2

- target: {fileID: 3644605328012301140, guid: 1cf3ef0a332884c299335f3fbe8a21fc,
- target: {fileID: 960518523084491425, guid: 1cf3ef0a332884c299335f3fbe8a21fc,
type: 3}
propertyPath: m_Name
value: Area
objectReference: {fileID: 0}
- target: {fileID: 6904544463179701055, guid: 1cf3ef0a332884c299335f3fbe8a21fc,
- target: {fileID: 3644605328012301140, guid: 1cf3ef0a332884c299335f3fbe8a21fc,
- target: {fileID: 6904544463179701055, guid: 1cf3ef0a332884c299335f3fbe8a21fc,
- target: {fileID: 3644605328012301140, guid: 1cf3ef0a332884c299335f3fbe8a21fc,
- target: {fileID: 6904544463179701055, guid: 1cf3ef0a332884c299335f3fbe8a21fc,
- target: {fileID: 3644605328012301140, guid: 1cf3ef0a332884c299335f3fbe8a21fc,
- target: {fileID: 6904544463179701055, guid: 1cf3ef0a332884c299335f3fbe8a21fc,
- target: {fileID: 3644605328012301140, guid: 1cf3ef0a332884c299335f3fbe8a21fc,
- target: {fileID: 6904544463179701055, guid: 1cf3ef0a332884c299335f3fbe8a21fc,
- target: {fileID: 3644605328012301140, guid: 1cf3ef0a332884c299335f3fbe8a21fc,
- target: {fileID: 6904544463179701055, guid: 1cf3ef0a332884c299335f3fbe8a21fc,
- target: {fileID: 3644605328012301140, guid: 1cf3ef0a332884c299335f3fbe8a21fc,
- target: {fileID: 6904544463179701055, guid: 1cf3ef0a332884c299335f3fbe8a21fc,
- target: {fileID: 3644605328012301140, guid: 1cf3ef0a332884c299335f3fbe8a21fc,
- target: {fileID: 6904544463179701055, guid: 1cf3ef0a332884c299335f3fbe8a21fc,
- target: {fileID: 3644605328012301140, guid: 1cf3ef0a332884c299335f3fbe8a21fc,
- target: {fileID: 6904544463179701055, guid: 1cf3ef0a332884c299335f3fbe8a21fc,
- target: {fileID: 3644605328012301140, guid: 1cf3ef0a332884c299335f3fbe8a21fc,
- target: {fileID: 6904544463179701055, guid: 1cf3ef0a332884c299335f3fbe8a21fc,
- target: {fileID: 3644605328012301140, guid: 1cf3ef0a332884c299335f3fbe8a21fc,
- target: {fileID: 6904544463179701055, guid: 1cf3ef0a332884c299335f3fbe8a21fc,
- target: {fileID: 3646225738314194020, guid: 1cf3ef0a332884c299335f3fbe8a21fc,
type: 3}
propertyPath: m_Name
value: Area
objectReference: {fileID: 0}
- target: {fileID: 3647717279211344790, guid: 1cf3ef0a332884c299335f3fbe8a21fc,
- target: {fileID: 8616498056362369282, guid: 1cf3ef0a332884c299335f3fbe8a21fc,
propertyPath: Settings.UseModelSpaceTranslations
value: 0
propertyPath: m_BrainParameters.VectorObservationSize
value: 9
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 1cf3ef0a332884c299335f3fbe8a21fc, type: 3}

2
Project/Assets/ML-Agents/Examples/Arena-Sequence/Scripts/SequenceTile.cs


public class SequenceTile : MonoBehaviour
{
public int NumberValue;
[HideInInspector]
public bool visited = false;
// [HideInInspector]
public MeshRenderer rend;

133
Project/Assets/ML-Agents/Examples/Arena-Sequence/Scripts/SequencerAgent.cs


public class SequencerAgent : Agent
{
// class TileInfo
// {
// public SequenceTile tile;
// public int SpawnIndexPos;
// }
public int NumberOfTilesToSpawn;
int m_NumberOfTilesToSpawn;
int m_MaxNumberOfTiles;
BufferSensorComponent m_BufferSensor;
public List<SequenceTile> SequenceTilesList = new List<SequenceTile>();
public List<SequenceTile> CurrentlyVisibleTilesList = new List<SequenceTile>();
private List<Transform> AlreadyTouchedList = new List<Transform>();

GameObject m_Area;
// private SequenceTile m_NextExpectedTile;

public override void Initialize()
{
m_Area = transform.parent.gameObject;
m_MaxNumberOfTiles = SequenceTilesList.Count;
m_BufferSensor = GetComponent<BufferSensorComponent>();
m_PushBlockSettings = FindObjectOfType<PushBlockSettings>();
m_AgentRb = GetComponent<Rigidbody>();
m_StartingPos = transform.position;

public override void OnEpisodeBegin()
{
m_NumberOfTilesToSpawn = Random.Range(1, m_MaxNumberOfTiles);
SelectTilesToShow();
SetTilePositions();

private void Update()
{
//DEBUG
if (SelectNewTiles)
{
SelectNewTiles = false;
SelectTilesToShow();
SetTilePositions();
}
////DEBUG
//if (SelectNewTiles)
//{
// SelectNewTiles = false;
// SelectTilesToShow();
// SetTilePositions();
//}
// foreach (var item in CurrentlyVisibleTilesList)
// {
// sensor.AddObservation(item.transform.localRotation.y / 360);
// }
sensor.AddObservation((transform.position.x - m_Area.transform.position.x) / 20f);
sensor.AddObservation((transform.position.z - m_Area.transform.position.z) / 20f);
sensor.AddObservation(transform.forward.x);
sensor.AddObservation(transform.forward.z);
foreach (var item in CurrentlyVisibleTilesList)
{
float[] listObservation = new float[m_MaxNumberOfTiles + 2];
listObservation[item.NumberValue] = 1.0f;
listObservation[m_MaxNumberOfTiles] = (item.transform.localRotation.eulerAngles.y / 360f);
listObservation[m_MaxNumberOfTiles + 1] = item.visited ? 1.0f : 0.0f;
//Debug.Log(listObservation[20]);
//Debug.Log(listObservation[21]);
//Debug.Log(listObservation[22]);
m_BufferSensor.AppendObservation(listObservation);
};
}
private void OnCollisionEnter(Collision col)

//failed
AddReward(-1);
EndEpisode();
print("no");
//print("no");
print("yes");
//print("yes");
tile.visited = true;
if (m_NextExpectedTileIndex == NumberOfTilesToSpawn)
if (m_NextExpectedTileIndex == m_NumberOfTilesToSpawn)
{
EndEpisode();
}

//Disable all. We will enable the ones selected
foreach (var item in SequenceTilesList)
{
item.visited = false;
item.gameObject.SetActive(false);
}

CurrentlyVisibleTilesList.Clear();
AlreadyTouchedList.Clear();
int numLeft = NumberOfTilesToSpawn;
int numLeft = m_NumberOfTilesToSpawn;
int rndInt = Random.Range(0, SequenceTilesList.Count);
int rndInt = Random.Range(0, m_MaxNumberOfTiles);
var tmp = SequenceTilesList[rndInt];
if (!CurrentlyVisibleTilesList.Contains(tmp))
{

//Sort Ascending
CurrentlyVisibleTilesList.Sort((x, y) => x.NumberValue.CompareTo(y.NumberValue));
// m_NextExpectedTile = CurrentlyVisibleTilesList[0];
m_NextExpectedTileIndex = 0;
}

var dirToGo = Vector3.zero;
var rotateDir = Vector3.zero;
var action = act[0];
var forwardAxis = act[0];
var rightAxis = act[1];
var rotateAxis = act[2];
switch (action)
switch (forwardAxis)
{
case 1:
dirToGo = transform.forward * 1f;

break;
case 3:
rotateDir = transform.up * 1f;
}
switch (rightAxis)
{
case 1:
dirToGo = transform.right * 1f;
case 4:
case 2:
dirToGo = transform.right * -1f;
break;
}
switch (rotateAxis)
{
case 1:
case 5:
dirToGo = transform.right * -0.75f;
break;
case 6:
dirToGo = transform.right * 0.75f;
case 2:
rotateDir = transform.up * 1f;
transform.Rotate(rotateDir, Time.fixedDeltaTime * 200f);
transform.Rotate(rotateDir, Time.deltaTime * 200f);
}
}
/// <summary>
/// Called every step of the engine. Here the agent takes an action.

public override void Heuristic(in ActionBuffers actionsOut)
{
var discreteActionsOut = actionsOut.DiscreteActions;
discreteActionsOut[0] = 0;
if (Input.GetKey(KeyCode.D))
var discreteActionsOut = actionsOut.DiscreteActions;
discreteActionsOut.Clear();
//forward
if (Input.GetKey(KeyCode.W))
{
discreteActionsOut[0] = 1;
}
if (Input.GetKey(KeyCode.S))
{
discreteActionsOut[0] = 2;
}
//rotate
if (Input.GetKey(KeyCode.A))
discreteActionsOut[0] = 3;
discreteActionsOut[2] = 1;
else if (Input.GetKey(KeyCode.W))
if (Input.GetKey(KeyCode.D))
discreteActionsOut[0] = 1;
discreteActionsOut[2] = 2;
else if (Input.GetKey(KeyCode.A))
//right
if (Input.GetKey(KeyCode.E))
discreteActionsOut[0] = 4;
discreteActionsOut[1] = 1;
else if (Input.GetKey(KeyCode.S))
if (Input.GetKey(KeyCode.Q))
discreteActionsOut[0] = 2;
discreteActionsOut[1] = 2;
}
}
}

2
Project/ProjectSettings/ProjectVersion.txt


m_EditorVersion: 2018.4.24f1
m_EditorVersion: 2018.4.20f1

2
com.unity.ml-agents/Runtime/Sensors/BufferSensor.cs


namespace Unity.MLAgents.Sensors
{
internal class BufferSensor : ISensor, IDimensionPropertiesSensor, IBuiltInSensor
public class BufferSensor : ISensor, IDimensionPropertiesSensor, IBuiltInSensor
{
private int m_MaxNumObs;
private int m_ObsSize;

2
com.unity.ml-agents/Runtime/Sensors/BufferSensorComponent.cs


/// A component for BufferSensor.
/// </summary>
[AddComponentMenu("ML Agents/Buffer Sensor", (int)MenuGroup.Sensors)]
internal class BufferSensorComponent : SensorComponent
public class BufferSensorComponent : SensorComponent
{
public int ObservableSize;
public int MaxNumObservables;

2
com.unity.ml-agents/Runtime/Sensors/IDimensionPropertiesSensor.cs


/// The Dimension property flags of the observations
/// </summary>
[System.Flags]
internal enum DimensionProperty
public enum DimensionProperty
{
/// <summary>
/// No properties specified.

28
config/ppo/Sorter.yaml


behaviors:
Sorter:
trainer_type: ppo
hyperparameters:
batch_size: 256
buffer_size: 10240
learning_rate: 0.0003
beta: 0.005
epsilon: 0.2
lambd: 0.95
num_epoch: 3
learning_rate_schedule: linear
network_settings:
normalize: False
hidden_units: 128
num_layers: 2
vis_encode_type: simple
reward_signals:
extrinsic:
gamma: 0.99
strength: 1.0
keep_checkpoints: 5
max_steps: 50000000
time_horizon: 512
summary_freq: 10000
threaded: true
env_settings:
num_envs: 8

8
Project/Assets/ML-Agents/Examples/Arena-Sequence/TFModels.meta


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