浏览代码

check for missing AbstractBoard, display warning (#5276) (#5278)

/release_17_branch
GitHub 4 年前
当前提交
260d55a0
共有 7 个文件被更改,包括 48 次插入0 次删除
  1. 4
      Project/Assets/ML-Agents/Examples/Match3/Scripts/Match3Drawer.cs
  2. 8
      com.unity.ml-agents/Editor/Match3ActuatorComponentEditor.cs
  3. 8
      com.unity.ml-agents/Editor/Match3SensorComponentEditor.cs
  4. 6
      com.unity.ml-agents/Runtime/Integrations/Match3/Match3ActuatorComponent.cs
  5. 4
      com.unity.ml-agents/Runtime/Integrations/Match3/Match3SensorComponent.cs
  6. 9
      com.unity.ml-agents/Tests/Editor/Integrations/Match3/Match3ActuatorTests.cs
  7. 9
      com.unity.ml-agents/Tests/Editor/Integrations/Match3/Match3SensorTests.cs

4
Project/Assets/ML-Agents/Examples/Match3/Scripts/Match3Drawer.cs


if (!m_Board)
{
m_Board = GetComponent<Match3Board>();
if (m_Board == null)
{
return;
}
}
var currentSize = m_Board.GetCurrentBoardSize();

8
com.unity.ml-agents/Editor/Match3ActuatorComponentEditor.cs


var so = serializedObject;
so.Update();
var component = (Match3ActuatorComponent)target;
var board = component.GetComponent<AbstractBoard>();
if (board == null)
{
EditorGUILayout.HelpBox("You must provide an implementation of an AbstractBoard.", MessageType.Warning);
return;
}
// Drawing the RenderTextureComponent
EditorGUI.BeginChangeCheck();

8
com.unity.ml-agents/Editor/Match3SensorComponentEditor.cs


var so = serializedObject;
so.Update();
var component = (Match3SensorComponent)target;
var board = component.GetComponent<AbstractBoard>();
if (board == null)
{
EditorGUILayout.HelpBox("You must provide an implementation of an AbstractBoard.", MessageType.Warning);
return;
}
// Drawing the RenderTextureComponent
EditorGUI.BeginChangeCheck();

6
com.unity.ml-agents/Runtime/Integrations/Match3/Match3ActuatorComponent.cs


using System;
using Unity.MLAgents.Actuators;
using UnityEngine;
using UnityEngine.Serialization;

public override IActuator[] CreateActuators()
{
var board = GetComponent<AbstractBoard>();
if (!board)
{
return Array.Empty<IActuator>();
}
var seed = m_RandomSeed == -1 ? gameObject.GetInstanceID() : m_RandomSeed + 1;
return new IActuator[] { new Match3Actuator(board, m_ForceHeuristic, seed, m_ActuatorName) };
}

4
com.unity.ml-agents/Runtime/Integrations/Match3/Match3SensorComponent.cs


Dispose();
var board = GetComponent<AbstractBoard>();
if (!board)
{
return Array.Empty<ISensor>();
}
var cellSensor = Match3Sensor.CellTypeSensor(board, m_ObservationType, m_SensorName + " (cells)");
// This can be null if numSpecialTypes is 0
var specialSensor = Match3Sensor.SpecialTypeSensor(board, m_ObservationType, m_SensorName + " (special)");

9
com.unity.ml-agents/Tests/Editor/Integrations/Match3/Match3ActuatorTests.cs


// And they should add up to all the potential moves
Assert.AreEqual(validIndices.Count + masks.HashSets[0].Count, board.NumMoves());
}
[Test]
public void TestNoBoardReturnsEmptyActuators()
{
var gameObj = new GameObject("board");
var actuatorComponent = gameObj.AddComponent<Match3ActuatorComponent>();
var actuators = actuatorComponent.CreateActuators();
Assert.AreEqual(0, actuators.Length);
}
}
}

9
com.unity.ml-agents/Tests/Editor/Integrations/Match3/Match3SensorTests.cs


return bytesOut.ToArray();
}
[Test]
public void TestNoBoardReturnsEmptySensors()
{
var gameObj = new GameObject("board");
var sensorComponent = gameObj.AddComponent<Match3SensorComponent>();
var sensors = sensorComponent.CreateSensors();
Assert.AreEqual(0, sensors.Length);
}
}
}
正在加载...
取消
保存