This commit is contained in:
Andrey Gumirov
2022-04-18 19:01:06 +07:00
parent e1d0bbc1eb
commit 4bd1e0644a
8 changed files with 54 additions and 22 deletions

View File

@ -1 +1 @@
{"count":1,"self":16.593504,"total":17.166309,"children":{"InitializeActuators":{"count":2,"self":0.0019996,"total":0.0019996,"children":null},"InitializeSensors":{"count":2,"self":0.0030004,"total":0.0030004,"children":null},"AgentSendState":{"count":612,"self":0.016998,"total":0.549809,"children":{"CollectObservations":{"count":1224,"self":0.0230042,"total":0.0230042,"children":null},"WriteActionMask":{"count":1224,"self":0.0060088,"total":0.0060088,"children":null},"RequestDecision":{"count":1224,"self":0.503798,"total":0.503798,"children":null}}},"DecideAction":{"count":612,"self":0.0089991,"total":0.0089991,"children":null},"AgentAct":{"count":612,"self":0.006997,"total":0.006997,"children":null}},"gauges":{"My Behavior.CumulativeReward":{"count":14,"max":0,"min":0,"runningAverage":0,"value":0,"weightedAverage":0}},"metadata":{"timer_format_version":"0.1.0","start_time_seconds":"1650253950","unity_version":"2019.4.35f1","command_line_arguments":"C:\\Program Files\\unityeditorfolder\\2019.4.35f1\\Editor\\Unity.exe -projectpath F:\\SigmaRiskManagment\\real shooter Git Version -useHub -hubIPC -cloudEnvironment production -licensingIpc LicenseClient-1IWpvtxiu_rvPpHhMWpzt -hubSessionId b1d8b690-be9f-11ec-92bc-6fd1276b6775 -accessToken D1AF5mitRE4Vh3s6p7rpmGuqcqvTsZJKmoGtSNfyNNs009f","communication_protocol_version":"1.5.0","com.unity.ml-agents_version":"2.0.1","scene_name":"Greatest_map_ever","end_time_seconds":"1650253967"}} {"count":1,"self":16.7881248,"total":28.869280999999997,"children":{"InitializeActuators":{"count":1,"self":0.0062039999999999994,"total":0.0062039999999999994,"children":null},"InitializeSensors":{"count":1,"self":0.009415,"total":0.009415,"children":null},"AgentInfo.ToProto":{"count":1,"self":0.0037809999999999996,"total":0.023178,"children":{"GenerateSensorData":{"count":1,"self":0.019396999999999998,"total":0.019396999999999998,"children":null}}},"AgentSendState":{"count":1094,"self":0.070126,"total":2.03434,"children":{"CollectObservations":{"count":1094,"self":1.694399,"total":1.694399,"children":null},"WriteActionMask":{"count":1094,"self":0.01526,"total":0.01526,"children":null},"RequestDecision":{"count":1094,"self":0.046751999999999995,"total":0.254555,"children":{"AgentInfo.ToProto":{"count":1094,"self":0.027583999999999997,"total":0.207803,"children":{"GenerateSensorData":{"count":1094,"self":0.180219,"total":0.180219,"children":null}}}}}}},"DecideAction":{"count":1094,"self":9.9110736,"total":9.911074,"children":null},"AgentAct":{"count":1094,"self":0.088208,"total":0.090377,"children":{"AgentInfo.ToProto":{"count":10,"self":0.00033,"total":0.002169,"children":{"GenerateSensorData":{"count":10,"self":0.001839,"total":0.001839,"children":null}}}}}},"gauges":{"npc.CumulativeReward":{"count":11,"max":0,"min":0,"runningAverage":0,"value":0,"weightedAverage":0}},"metadata":{"timer_format_version":"0.1.0","start_time_seconds":"1650283028","unity_version":"2019.4.36f1","command_line_arguments":"\/Applications\/Unity\/Hub\/Editor\/2019.4.36f1\/Unity.app\/Contents\/MacOS\/Unity -projectpath \/Users\/gav\/tmp\/projects\/real-shooter -useHub -hubIPC -cloudEnvironment production -licensingIpc LicenseClient-gav -hubSessionId 3b1d3b50-bef1-11ec-a2f1-7fead03718a2 -accessToken r8bZAeodsmy_r-5SjXH5Fv1-VHYleg9acf27P9OS5KU009f","communication_protocol_version":"1.5.0","com.unity.ml-agents_version":"2.0.1","scene_name":"Greatest_map_ever","end_time_seconds":"1650283056"}}

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

@ -143,19 +143,19 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
m_BrainParameters: m_BrainParameters:
VectorObservationSize: 1 VectorObservationSize: 4
NumStackedVectorObservations: 1 NumStackedVectorObservations: 1
m_ActionSpec: m_ActionSpec:
m_NumContinuousActions: 0 m_NumContinuousActions: 0
BranchSizes: 01000000 BranchSizes: 0200000002000000
VectorActionSize: 01000000 VectorActionSize: 0200000002000000
VectorActionDescriptions: [] VectorActionDescriptions: []
VectorActionSpaceType: 0 VectorActionSpaceType: 0
hasUpgradedBrainParametersWithActionSpec: 1 hasUpgradedBrainParametersWithActionSpec: 1
m_Model: {fileID: 0} m_Model: {fileID: 0}
m_InferenceDevice: 0 m_InferenceDevice: 0
m_BehaviorType: 0 m_BehaviorType: 0
m_BehaviorName: My Behavior m_BehaviorName: npc
TeamId: 0 TeamId: 0
m_UseChildSensors: 1 m_UseChildSensors: 1
m_UseChildActuators: 1 m_UseChildActuators: 1
@ -209,4 +209,4 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
m_SensorName: BufferSensor m_SensorName: BufferSensor
m_ObservableSize: 5 m_ObservableSize: 5
m_MaxNumObservables: 512 m_MaxNumObservables: 5

13
Assets/Scenes/Greatest_map_ever/Greatest_map_ever.unity generated Executable file → Normal file
View File

@ -38,7 +38,7 @@ RenderSettings:
m_ReflectionIntensity: 1 m_ReflectionIntensity: 1
m_CustomReflection: {fileID: 0} m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 705507994} m_Sun: {fileID: 705507994}
m_IndirectSpecularColor: {r: 0.44657898, g: 0.4964133, b: 0.5748178, a: 1} m_IndirectSpecularColor: {r: 0.44657815, g: 0.49641192, b: 0.57481617, a: 1}
m_UseRadianceAmbientProbe: 0 m_UseRadianceAmbientProbe: 0
--- !u!157 &3 --- !u!157 &3
LightmapSettings: LightmapSettings:
@ -259,6 +259,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 6a2d29bfc31a8cf4e831e3bb80720414, type: 3} m_Script: {fileID: 11500000, guid: 6a2d29bfc31a8cf4e831e3bb80720414, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
PointId: 0
DeathAttr: 0 DeathAttr: 0
EnemiesSeen: [] EnemiesSeen: []
--- !u!23 &140697607 --- !u!23 &140697607
@ -353,6 +354,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 6a2d29bfc31a8cf4e831e3bb80720414, type: 3} m_Script: {fileID: 11500000, guid: 6a2d29bfc31a8cf4e831e3bb80720414, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
PointId: 0
DeathAttr: 0 DeathAttr: 0
EnemiesSeen: [] EnemiesSeen: []
--- !u!23 &293522541 --- !u!23 &293522541
@ -1315,6 +1317,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 6a2d29bfc31a8cf4e831e3bb80720414, type: 3} m_Script: {fileID: 11500000, guid: 6a2d29bfc31a8cf4e831e3bb80720414, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
PointId: 0
DeathAttr: 0 DeathAttr: 0
EnemiesSeen: [] EnemiesSeen: []
--- !u!23 &1116745545 --- !u!23 &1116745545
@ -1745,7 +1748,7 @@ Transform:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1345085340} m_GameObject: {fileID: 1345085340}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 47.446796, y: -5.782543, z: -25.400002} m_LocalPosition: {x: 21.51, y: -5.782543, z: -10.46}
m_LocalScale: {x: 1.4367, y: 1.4367, z: 1.4367} m_LocalScale: {x: 1.4367, y: 1.4367, z: 1.4367}
m_Children: [] m_Children: []
m_Father: {fileID: 2060099472} m_Father: {fileID: 2060099472}
@ -1763,6 +1766,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 6a2d29bfc31a8cf4e831e3bb80720414, type: 3} m_Script: {fileID: 11500000, guid: 6a2d29bfc31a8cf4e831e3bb80720414, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
PointId: 0
DeathAttr: 0 DeathAttr: 0
EnemiesSeen: [] EnemiesSeen: []
--- !u!23 &1345085343 --- !u!23 &1345085343
@ -1857,6 +1861,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 6a2d29bfc31a8cf4e831e3bb80720414, type: 3} m_Script: {fileID: 11500000, guid: 6a2d29bfc31a8cf4e831e3bb80720414, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
PointId: 0
DeathAttr: 0 DeathAttr: 0
EnemiesSeen: [] EnemiesSeen: []
--- !u!23 &1488699524 --- !u!23 &1488699524
@ -2077,6 +2082,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 6a2d29bfc31a8cf4e831e3bb80720414, type: 3} m_Script: {fileID: 11500000, guid: 6a2d29bfc31a8cf4e831e3bb80720414, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
PointId: 0
DeathAttr: 0 DeathAttr: 0
EnemiesSeen: [] EnemiesSeen: []
--- !u!23 &1663305224 --- !u!23 &1663305224
@ -2251,7 +2257,7 @@ MonoBehaviour:
- {fileID: 2004854094} - {fileID: 2004854094}
AIPrefab: {fileID: 2988578997639256874, guid: b016874eb34cc084aa4359f0bbec50e1, AIPrefab: {fileID: 2988578997639256874, guid: b016874eb34cc084aa4359f0bbec50e1,
type: 3} type: 3}
PlayerPrefab: {fileID: 5245491127989480125, guid: 80f6c1c85e5daed4c96c70205ed5503d, PlayerPrefab: {fileID: 5245491127989480125, guid: 99bb17a23a489624baeaf337f91a4f84,
type: 3} type: 3}
--- !u!1 &1871257865 --- !u!1 &1871257865
GameObject: GameObject:
@ -2506,6 +2512,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 6a2d29bfc31a8cf4e831e3bb80720414, type: 3} m_Script: {fileID: 11500000, guid: 6a2d29bfc31a8cf4e831e3bb80720414, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
PointId: 0
DeathAttr: 0 DeathAttr: 0
EnemiesSeen: [] EnemiesSeen: []
--- !u!23 &2004854095 --- !u!23 &2004854095

View File

@ -9,6 +9,7 @@ public class CharacterCondition
public event Action<int> OnChangeAmmunitionEvent; public event Action<int> OnChangeAmmunitionEvent;
private int health; private int health;
public int HealthPoints public int HealthPoints
{ {
get get

View File

@ -7,13 +7,28 @@ using UnityEngine.AI;
public class MovementController : MonoBehaviour public class MovementController : MonoBehaviour
{ {
public NavPoint currentPosition { get; set; } public NavPoint currentPosition { get; set; }
private Dictionary<int, NavPoint> navPoints = new Dictionary<int, NavPoint>();
[SerializeField] private NavMeshAgent navMeshAgent; [SerializeField] private NavMeshAgent navMeshAgent;
private void Start() private void Start()
{ {
navMeshAgent.speed = SettingsReader.Instance.GetSettings.movementSpeed; navMeshAgent.speed = SettingsReader.Instance.GetSettings.movementSpeed;
foreach (var np in MapManager.navPoints) {
navPoints[np.PointId] = np;
}
} }
public void MoveToPointById(int id)
{
if (!navPoints.ContainsKey(id))
{
Debug.LogWarning("PIDOR");
return;
}
goToNextNavPoint(navPoints[id]);
}
public void MoveToRandomPoint() public void MoveToRandomPoint()
{ {
Debug.Log(MapManager.navPoints == null); Debug.Log(MapManager.navPoints == null);
@ -23,7 +38,7 @@ public class MovementController : MonoBehaviour
public List<NavPoint> getPointsCandidate() public List<NavPoint> getPointsCandidate()
{ {
return MapManager.navPoints return MapManager.navPoints
.Where(point => (currentPosition.position - point.position).magnitude < SettingsReader.Instance.GetSettings.movementSpeed) .Where(point => (currentPosition.position - point.position).magnitude < SettingsReader.Instance.GetSettings.movementDistance)
.ToList(); .ToList();
} }

View File

@ -54,24 +54,29 @@ public class NPC : Agent, ICharacter
sensor.AddObservation(Condition.HealthPoints); sensor.AddObservation(Condition.HealthPoints);
sensor.AddObservation(Condition.ArmourPoints); sensor.AddObservation(Condition.ArmourPoints);
sensor.AddObservation(Condition.Ammunition); sensor.AddObservation(Condition.Ammunition);
sensor.AddObservation((int)NPC_State.State); sensor.AddObservation((int) NPC_State.State);
var candidates = moveController.getPointsCandidate(); var candidates = moveController.getPointsCandidate();
foreach (var point in candidates) foreach (var point in candidates)
{ {
bufferSensor.AppendObservation(new float[] { var parray = new float[]
{
//1 position in navpointId //1 position in navpointId
(float)moveController.currentPosition.PointId, (float) moveController.currentPosition.PointId,
//2 distance to flag //2 distance to flag
moveController.currentPosition.FlagDistance, moveController.currentPosition.FlagDistance,
//3 death count in point //3 death count in point
moveController.currentPosition.DeathAttr, moveController.currentPosition.DeathAttr,
//4 flagEnemyDistance //4 flagEnemyDistance
GameManager.IsCloserToFlagFromNextNavPoint(point, transform.position)==true?1:0, GameManager.IsCloserToFlagFromNextNavPoint(point, transform.position) == true ? 1 : 0,
//5 EnemyVsNavPointDistance //5 EnemyVsNavPointDistance
GameManager.IsCloserToEnemyThanToNextNavPoint(point,transform.position, AgentCharacter.Team)==true?1:0 GameManager.IsCloserToEnemyThanToNextNavPoint(point, transform.position, AgentCharacter.Team) == true
}); ? 1
: 0
};
var _parray = string.Join(" ", parray);
Debug.Log("OBS: " + _parray);
bufferSensor.AppendObservation(parray);
} }
} }
@ -90,6 +95,9 @@ public class NPC : Agent, ICharacter
{ {
moveController.MoveToRandomPoint(); moveController.MoveToRandomPoint();
NPC_State = RunningState; NPC_State = RunningState;
} else if (actions.DiscreteActions[0] == 2)
{
moveController.MoveToPointById(actions.DiscreteActions[1]);
} }
} }

View File

@ -8,13 +8,14 @@ public class NavPoint : MonoBehaviour
public float FlagDistance { get; private set; } public float FlagDistance { get; private set; }
[HideInInspector] [HideInInspector]
public int? PointId; public int PointId;
public float DeathAttr = 0; public float DeathAttr = 0;
public List<Vector3> EnemiesSeen = new List<Vector3>(); public List<Vector3> EnemiesSeen = new List<Vector3>();
//Here other attributes; //Here other attributes;
private void Start() private void Start()
{ {
PointId = GetInstanceID();
FlagDistance = (GameObject.FindGameObjectWithTag("Flag").transform.position - position).magnitude; FlagDistance = (GameObject.FindGameObjectWithTag("Flag").transform.position - position).magnitude;
} }
} }

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

@ -27,9 +27,9 @@ MonoBehaviour:
armourPickupAmount: 50 armourPickupAmount: 50
ammunitionPickupAmount: 120 ammunitionPickupAmount: 120
pickupsAmount: 2 pickupsAmount: 2
maxHealth: 0 maxHealth: 100
maxArmour: 0 maxArmour: 100
maxAmmo: 0 maxAmmo: 31337
GetHitChanceInDirectPoint: 0 GetHitChanceInDirectPoint: 0
GetHitChanceInRunning: 0 GetHitChanceInRunning: 0
GetHitChanceInCover: 0 GetHitChanceInCover: 0