| using System; |
| using Unity.MLAgents.Actuators; |
| using UnityEngine; |
| using UnityEngine.Serialization; |
|
|
| namespace Unity.MLAgents.Integrations.Match3 |
| { |
| |
| |
| |
| [AddComponentMenu("ML Agents/Match 3 Actuator", (int)MenuGroup.Actuators)] |
| public class Match3ActuatorComponent : ActuatorComponent |
| { |
| [HideInInspector, SerializeField, FormerlySerializedAs("ActuatorName")] |
| string m_ActuatorName = "Match3 Actuator"; |
|
|
| |
| |
| |
| |
| public string ActuatorName |
| { |
| get => m_ActuatorName; |
| set => m_ActuatorName = value; |
| } |
|
|
| [HideInInspector, SerializeField, FormerlySerializedAs("RandomSeed")] |
| int m_RandomSeed = -1; |
|
|
| |
| |
| |
| public int RandomSeed |
| { |
| get => m_RandomSeed; |
| set => m_RandomSeed = value; |
| } |
|
|
| [HideInInspector, SerializeField, FormerlySerializedAs("ForceHeuristic")] |
| [Tooltip("Force using the Agent's Heuristic() method to decide the action. This should only be used in testing.")] |
| bool m_ForceHeuristic; |
|
|
| |
| |
| |
| public bool ForceHeuristic |
| { |
| get => m_ForceHeuristic; |
| set => m_ForceHeuristic = value; |
| } |
|
|
| int CreateNewSeed() |
| { |
| #if UNITY_6000_3_OR_NEWER |
| return gameObject.GetEntityId().GetHashCode(); |
| #else |
| return gameObject.GetInstanceID(); |
| #endif |
| } |
|
|
| |
| public override IActuator[] CreateActuators() |
| { |
| var board = GetComponent<AbstractBoard>(); |
| if (!board) |
| { |
| return Array.Empty<IActuator>(); |
| } |
|
|
| var seed = m_RandomSeed == -1 ? CreateNewSeed() : m_RandomSeed + 1; |
| return new IActuator[] { new Match3Actuator(board, m_ForceHeuristic, seed, m_ActuatorName) }; |
| } |
|
|
| |
| public override ActionSpec ActionSpec |
| { |
| get |
| { |
| var board = GetComponent<AbstractBoard>(); |
| if (board == null) |
| { |
| return ActionSpec.MakeContinuous(0); |
| } |
|
|
| var numMoves = Move.NumPotentialMoves(board.GetMaxBoardSize()); |
| return ActionSpec.MakeDiscrete(numMoves); |
| } |
| } |
| } |
| } |
|
|