...
This commit is contained in:
@ -4,6 +4,7 @@ using Unity.MLAgents;
|
||||
using Unity.MLAgents.Sensors;
|
||||
using Unity.MLAgents.Actuators;
|
||||
using System.Collections.Generic;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
[RequireComponent(typeof(MovementController))]
|
||||
public class NPC : Agent, ICharacter
|
||||
@ -21,6 +22,9 @@ public class NPC : Agent, ICharacter
|
||||
private MovementController moveController;
|
||||
private BufferSensorComponent bufferSensor;
|
||||
|
||||
[SerializeField] [NotNull]
|
||||
private NavPoint DumbAIDestination;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
DirectState = new NPC_DirectPointState();
|
||||
@ -31,6 +35,7 @@ public class NPC : Agent, ICharacter
|
||||
AgentCharacter = new Character();
|
||||
Condition = AgentCharacter.Condition;
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
AgentCharacter = new Character();
|
||||
@ -44,7 +49,7 @@ public class NPC : Agent, ICharacter
|
||||
|
||||
public override void OnEpisodeBegin()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
public override void CollectObservations(VectorSensor sensor)
|
||||
@ -52,7 +57,7 @@ public class NPC : Agent, ICharacter
|
||||
sensor.AddObservation(Condition.HealthPoints);
|
||||
sensor.AddObservation(Condition.ArmourPoints);
|
||||
sensor.AddObservation(Condition.Ammunition);
|
||||
sensor.AddObservation((int)NPC_State.State);
|
||||
sensor.AddObservation((int) NPC_State.State);
|
||||
|
||||
|
||||
|
||||
@ -60,32 +65,36 @@ public class NPC : Agent, ICharacter
|
||||
foreach (var point in candidates)
|
||||
{
|
||||
|
||||
bufferSensor.AppendObservation(new float[] {
|
||||
bufferSensor.AppendObservation(new float[]
|
||||
{
|
||||
//1 position in navpointId
|
||||
(float)moveController.currentPosition.PointId,
|
||||
(float) moveController.currentPosition.PointId,
|
||||
//2 distance to flag
|
||||
moveController.currentPosition.FlagDistance,
|
||||
//3 death count in point
|
||||
moveController.currentPosition.DeathAttr,
|
||||
//4 flagEnemyDistance
|
||||
GameManager.IsCloserToFlagFromNextNavPoint(point, transform.position)==true?1:0,
|
||||
GameManager.IsCloserToFlagFromNextNavPoint(point, transform.position) == true ? 1 : 0,
|
||||
//5 EnemyVsNavPointDistance
|
||||
GameManager.IsCloserToEnemyThanToNextNavPoint(point,transform.position, AgentCharacter.Team)==true?1:0
|
||||
});
|
||||
GameManager.IsCloserToEnemyThanToNextNavPoint(point, transform.position, AgentCharacter.Team) == true
|
||||
? 1
|
||||
: 0
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public override void Heuristic(in ActionBuffers actionsOut)
|
||||
{
|
||||
var discreteActionsOut = actionsOut.DiscreteActions;
|
||||
if (Input.GetKeyDown(KeyCode.W))
|
||||
{
|
||||
discreteActionsOut[0] = 1;
|
||||
}
|
||||
moveController.goToNextNavPoint(DumbAIDestination);
|
||||
}
|
||||
|
||||
public override void OnActionReceived(ActionBuffers actions)
|
||||
public void DumbAIAction()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void OnActionReceived(ActionBuffers actions)
|
||||
{
|
||||
if (actions.DiscreteActions[0] == 1)
|
||||
{
|
||||
|
Reference in New Issue
Block a user