using Unity.MLAgents.Actuators;
using UnityEngine;
using UnityEngine.Serialization;
namespace Unity.MLAgents.Extensions.Match3
{
///
/// Actuator component for a Match3 game. Generates a Match3Actuator at runtime.
///
public class Match3ActuatorComponent : ActuatorComponent
{
///
/// Name of the generated Match3Actuator object.
/// Note that changing this at runtime does not affect how the Agent sorts the actuators.
///
public string ActuatorName = "Match3 Actuator";
///
/// A random seed used to generate a board, if needed.
///
public int RandomSeed = -1;
///
/// Force using the Agent's Heuristic() method to decide the action. This should only be used in testing.
///
[FormerlySerializedAs("ForceRandom")]
[Tooltip("Force using the Agent's Heuristic() method to decide the action. This should only be used in testing.")]
public bool ForceHeuristic;
///
public override IActuator CreateActuator()
{
var board = GetComponent();
var agent = GetComponentInParent();
var seed = RandomSeed == -1 ? gameObject.GetInstanceID() : RandomSeed + 1;
return new Match3Actuator(board, ForceHeuristic, seed, agent, ActuatorName);
}
///
public override ActionSpec ActionSpec
{
get
{
var board = GetComponent();
if (board == null)
{
return ActionSpec.MakeContinuous(0);
}
var numMoves = Move.NumPotentialMoves(board.Rows, board.Columns);
return ActionSpec.MakeDiscrete(numMoves);
}
}
}
}