MVP work with ml-agents python library
This commit is contained in:
@ -73,6 +73,7 @@ public class NPC : Agent, ICharacter
|
||||
|
||||
public override void CollectObservations(VectorSensor sensor)
|
||||
{
|
||||
// Debug.Log("Collect observations called!");
|
||||
navPointIdDict = MapManager.Instance.IDToNavPoint;
|
||||
if (navPointIdDict is null)
|
||||
Debug.LogError("Cant Find Nav Point Dictionary");
|
||||
@ -88,6 +89,7 @@ public class NPC : Agent, ICharacter
|
||||
sensor.AddObservation(candidates.Count);
|
||||
sensor.AddObservation(moveController.PointStartID);
|
||||
sensor.AddObservation(moveController.PointEndID);
|
||||
// Debug.Log("Done common!");
|
||||
//state sensors
|
||||
sensor.AddObservation((int)NpcState.State);
|
||||
sensor.AddObservation((int)NpcBodyState.State);
|
||||
@ -95,6 +97,7 @@ public class NPC : Agent, ICharacter
|
||||
sensor.AddObservation(navPointIdDict[moveController.PointStartID].DeathAttr);
|
||||
sensor.AddObservation(navPointIdDict[moveController.PointEndID].DeathAttr);
|
||||
sensor.AddObservation(moveController.FlagDistance);
|
||||
// Debug.Log("Done state sensors!");
|
||||
|
||||
//point sensors
|
||||
foreach (var point in candidates)
|
||||
@ -112,11 +115,14 @@ public class NPC : Agent, ICharacter
|
||||
point.Position).ToInt()
|
||||
});
|
||||
}
|
||||
// Debug.Log("Done collect observations!");
|
||||
}
|
||||
|
||||
public override void OnActionReceived(ActionBuffers actions)
|
||||
{
|
||||
// Debug.Log("Actions recieved!");
|
||||
var result = actions.DiscreteActions;
|
||||
// Debug.Log(result[0] + " " + result[1]);
|
||||
if (result[0] == 0)
|
||||
{
|
||||
if (navPointIdDict[moveController.PointStartID].navType != NavPointType.Cover)
|
||||
@ -132,18 +138,26 @@ public class NPC : Agent, ICharacter
|
||||
default: throw new ArgumentException("Undefined Action recieved");
|
||||
}
|
||||
}
|
||||
// Debug.Log(result[0] == 1);
|
||||
if (result[0] == 1)
|
||||
{
|
||||
// Debug.Log("BEFORE SOme shitty if >:(");
|
||||
if (navPointIdDict[moveController.PointStartID].navType != NavPointType.Direction)
|
||||
{
|
||||
// Debug.Log("SOme shitty if >:(");
|
||||
return;
|
||||
}
|
||||
// Debug.Log("FUCK");
|
||||
|
||||
switch (result[1])
|
||||
{
|
||||
case 0: moveController.GoToNextNavPoint(navPointIdDict[result[2]]);
|
||||
NpcState = RunningState; break;
|
||||
NpcState = RunningState; Debug.Log("Go to point " + result[2]);break;
|
||||
case 1: NpcState = DirectState; break;
|
||||
default: throw new ArgumentException("Undefined Action recieved");
|
||||
}
|
||||
}
|
||||
|
||||
if (result[0] == 2)
|
||||
{
|
||||
if (moveController.PointStartID == moveController.PointEndID && moveController.PointEndID != -1)
|
||||
@ -155,6 +169,7 @@ public class NPC : Agent, ICharacter
|
||||
default: throw new ArgumentException("Undefined Action recieved");
|
||||
}
|
||||
}
|
||||
// Debug.Log("Actions processed!");
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
Reference in New Issue
Block a user