using Unity.MLAgents.Sensors;
namespace Unity.MLAgents.Extensions.Match3
{
///
/// Sensor component for a Match3 game.
///
public class Match3SensorComponent : SensorComponent
{
///
/// Name of the generated Match3Sensor object.
/// Note that changing this at runtime does not affect how the Agent sorts the sensors.
///
public string SensorName = "Match3 Sensor";
///
/// Type of observation to generate.
///
public Match3ObservationType ObservationType = Match3ObservationType.Vector;
///
public override ISensor CreateSensor()
{
var board = GetComponent();
return new Match3Sensor(board, ObservationType, SensorName);
}
///
public override int[] GetObservationShape()
{
var board = GetComponent();
if (board == null)
{
return System.Array.Empty();
}
var specialSize = board.NumSpecialTypes == 0 ? 0 : board.NumSpecialTypes + 1;
return ObservationType == Match3ObservationType.Vector ?
new[] { board.Rows * board.Columns * (board.NumCellTypes + specialSize) } :
new[] { board.Rows, board.Columns, board.NumCellTypes + specialSize };
}
}
}