Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ void OnDrawGizmos()
if (!m_Board)
{
m_Board = GetComponent<Match3Board>();
if (m_Board == null)
{
return;
}
}

var currentSize = m_Board.GetCurrentBoardSize();
Expand Down
8 changes: 8 additions & 0 deletions com.unity.ml-agents/Editor/Match3ActuatorComponentEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ public override void OnInspectorGUI()
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();

Expand Down
8 changes: 8 additions & 0 deletions com.unity.ml-agents/Editor/Match3SensorComponentEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ public override void OnInspectorGUI()
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();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using Unity.MLAgents.Actuators;
using UnityEngine;
using UnityEngine.Serialization;
Expand Down Expand Up @@ -52,6 +53,11 @@ public bool ForceHeuristic
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) };
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ public override ISensor[] CreateSensors()
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)");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,5 +194,14 @@ public void TestMasking(bool fullBoard)
// 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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -395,5 +395,14 @@ byte[] LoadPNGs(string pathPrefix, int numExpected)

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);
}
}
}