61 lines
1.7 KiB
C#
61 lines
1.7 KiB
C#
|
using UnityEngine;
|
||
|
using Unity.MLAgents;
|
||
|
using Unity.MLAgents.Actuators;
|
||
|
using Unity.MLAgents.Sensors;
|
||
|
using System.Collections.Generic;
|
||
|
using Unity.MLAgents.Policies;
|
||
|
using Unity.VisualScripting;
|
||
|
using Unity.Barracuda;
|
||
|
|
||
|
public class ObserverBehaviour : PlayerBehaviour
|
||
|
{
|
||
|
private ObserverAI _observerAi;
|
||
|
private BehaviorParameters _behaviourParameters;
|
||
|
|
||
|
protected override void Awake()
|
||
|
{
|
||
|
base.Awake();
|
||
|
|
||
|
_observerAi = _playerRef.gameObject.AddComponent<ObserverAI>();
|
||
|
_observerAi.enabled = false;
|
||
|
_behaviourParameters = _playerRef.gameObject.GetComponent<BehaviorParameters>();// ?? _playerRef.gameObject.AddComponent<BehaviorParameters>();
|
||
|
_behaviourParameters.BehaviorName = "Observer";
|
||
|
_behaviourParameters.BrainParameters.VectorObservationSize = 29;
|
||
|
_behaviourParameters.BrainParameters.ActionSpec =
|
||
|
//new ActionSpec(
|
||
|
// numContinuousActions: 1, // Une seule action continue
|
||
|
// discreteBranchSizes: new int[] { 0 } // Une action discrète avec 0 choix possibles
|
||
|
// );
|
||
|
ActionSpec.MakeContinuous(1);
|
||
|
|
||
|
_behaviourParameters.Model = Resources.Load<NNModel>("Observer");
|
||
|
|
||
|
|
||
|
_observerAi.EndEpisode();
|
||
|
_observerAi.enabled = true;
|
||
|
}
|
||
|
|
||
|
protected override sbyte ChooseDirection()
|
||
|
{
|
||
|
var direction = _observerAi.TakeDecision();
|
||
|
|
||
|
return direction;
|
||
|
}
|
||
|
|
||
|
|
||
|
protected override string ChoosePlayerName()
|
||
|
{
|
||
|
return "Bot Observateur";
|
||
|
}
|
||
|
|
||
|
protected override Color ChoosePlayerColor()
|
||
|
{
|
||
|
return new Color(0, 255, 0);
|
||
|
}
|
||
|
|
||
|
protected override bool ChooseIfPlayerIsHuman()
|
||
|
{
|
||
|
return false;
|
||
|
}
|
||
|
}
|