MVP work with ml-agents python library

This commit is contained in:
Andrey Gumirov
2022-05-07 22:56:07 +07:00
parent 8083501783
commit 8cce356b8e
7 changed files with 129 additions and 9 deletions

27
Assets/Prefabs/Bot.prefab generated Executable file → Normal file
View File

@ -50,6 +50,7 @@ GameObject:
- component: {fileID: 2756943273076691504}
- component: {fileID: 6638271233700792696}
- component: {fileID: 5988018701276467001}
- component: {fileID: 1547882613481475944}
m_Layer: 8
m_Name: Bot
m_TagString: Defender
@ -210,8 +211,8 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
m_SensorName: BufferSensor
m_ObservableSize: 0
m_MaxNumObservables: 0
m_ObservableSize: 5
m_MaxNumObservables: 10
--- !u!114 &2756943273076691504
MonoBehaviour:
m_ObjectHideFlags: 0
@ -225,19 +226,19 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
m_BrainParameters:
VectorObservationSize: 1
VectorObservationSize: 14
NumStackedVectorObservations: 1
m_ActionSpec:
m_NumContinuousActions: 0
BranchSizes: 01000000
VectorActionSize: 01000000
BranchSizes: 010000000100000001000000
VectorActionSize: 010000000100000001000000
VectorActionDescriptions: []
VectorActionSpaceType: 0
hasUpgradedBrainParametersWithActionSpec: 1
m_Model: {fileID: 0}
m_InferenceDevice: 0
m_BehaviorType: 0
m_BehaviorName: My Behavior
m_BehaviorName: npc
TeamId: 0
m_UseChildSensors: 1
m_UseChildActuators: 1
@ -272,3 +273,17 @@ MonoBehaviour:
m_EditorClassIdentifier:
navMeshAgent: {fileID: 8774702625908438859}
flag: {fileID: 6818223691859422291, guid: 1685c1d9ce4ab174f95c646b1826010b, type: 3}
--- !u!114 &1547882613481475944
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6171680323948707524}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 3a5c9d521e5ef4759a8246a07d52221e, type: 3}
m_Name:
m_EditorClassIdentifier:
DecisionPeriod: 5
TakeActionsBetweenDecisions: 0

2
Assets/Prefabs/Player.prefab.meta generated Executable file → Normal file
View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 80f6c1c85e5daed4c96c70205ed5503d
guid: a7480b77908b042d8adcdd84e8c2c15e
PrefabImporter:
externalObjects: {}
userData:

View File

@ -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

0
Assets/Settings/Game Settings.asset generated Executable file → Normal file
View File

View File

@ -1,17 +1,24 @@
{
"dependencies": {
"com.unity.2d.sprite": "1.0.0",
"com.unity.2d.tilemap": "1.0.0",
"com.unity.ads": "3.7.5",
"com.unity.analytics": "3.6.12",
"com.unity.collab-proxy": "1.14.12",
"com.unity.ide.rider": "1.2.1",
"com.unity.ide.visualstudio": "2.0.14",
"com.unity.ide.vscode": "1.2.4",
"com.unity.inputsystem": "1.3.0",
"com.unity.ml-agents": "2.0.1",
"com.unity.multiplayer-hlapi": "1.0.8",
"com.unity.probuilder": "4.5.2",
"com.unity.purchasing": "4.1.2",
"com.unity.test-framework": "1.1.30",
"com.unity.textmeshpro": "2.1.6",
"com.unity.timeline": "1.2.18",
"com.unity.toolchain.win-x86_64-linux-x86_64": "2.0.0",
"com.unity.ugui": "1.0.0",
"com.unity.xr.legacyinputhelpers": "2.1.8",
"com.unity.modules.ai": "1.0.0",
"com.unity.modules.androidjni": "1.0.0",
"com.unity.modules.animation": "1.0.0",

View File

@ -1,5 +1,35 @@
{
"dependencies": {
"com.unity.2d.sprite": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {}
},
"com.unity.2d.tilemap": {
"version": "1.0.0",
"depth": 0,
"source": "builtin",
"dependencies": {}
},
"com.unity.ads": {
"version": "3.7.5",
"depth": 0,
"source": "registry",
"dependencies": {
"com.unity.ugui": "1.0.0"
},
"url": "https://packages.unity.com"
},
"com.unity.analytics": {
"version": "3.6.12",
"depth": 0,
"source": "registry",
"dependencies": {
"com.unity.ugui": "1.0.0"
},
"url": "https://packages.unity.com"
},
"com.unity.barracuda": {
"version": "2.0.0",
"depth": 1,
@ -86,6 +116,15 @@
},
"url": "https://packages.unity.com"
},
"com.unity.multiplayer-hlapi": {
"version": "1.0.8",
"depth": 0,
"source": "registry",
"dependencies": {
"nuget.mono-cecil": "0.1.6-preview"
},
"url": "https://packages.unity.com"
},
"com.unity.probuilder": {
"version": "4.5.2",
"depth": 0,
@ -95,6 +134,29 @@
},
"url": "https://packages.unity.com"
},
"com.unity.purchasing": {
"version": "4.1.2",
"depth": 0,
"source": "registry",
"dependencies": {
"com.unity.ugui": "1.0.0",
"com.unity.modules.unityanalytics": "1.0.0",
"com.unity.modules.unitywebrequest": "1.0.0",
"com.unity.modules.jsonserialize": "1.0.0",
"com.unity.modules.androidjni": "1.0.0",
"com.unity.services.core": "1.0.1"
},
"url": "https://packages.unity.com"
},
"com.unity.services.core": {
"version": "1.0.1",
"depth": 1,
"source": "registry",
"dependencies": {
"com.unity.modules.unitywebrequest": "1.0.0"
},
"url": "https://packages.unity.com"
},
"com.unity.settings-manager": {
"version": "1.0.3",
"depth": 1,
@ -169,6 +231,23 @@
"com.unity.modules.imgui": "1.0.0"
}
},
"com.unity.xr.legacyinputhelpers": {
"version": "2.1.8",
"depth": 0,
"source": "registry",
"dependencies": {
"com.unity.modules.vr": "1.0.0",
"com.unity.modules.xr": "1.0.0"
},
"url": "https://packages.unity.com"
},
"nuget.mono-cecil": {
"version": "0.1.6-preview",
"depth": 1,
"source": "registry",
"dependencies": {},
"url": "https://packages.unity.com"
},
"com.unity.modules.ai": {
"version": "1.0.0",
"depth": 0,

View File

@ -614,7 +614,11 @@ PlayerSettings:
webGLLinkerTarget: 1
webGLThreadsSupport: 0
webGLWasmStreaming: 0
scriptingDefineSymbols: {}
scriptingDefineSymbols:
1: CROSS_PLATFORM_INPUT
4: CROSS_PLATFORM_INPUT;MOBILE_INPUT
7: CROSS_PLATFORM_INPUT;MOBILE_INPUT
14: MOBILE_INPUT
platformArchitecture: {}
scriptingBackend: {}
il2cppCompilerConfiguration: {}