Skip to content

Commit

Permalink
【MA基礎開発】簡易シミュレータの調整。一部報酬定義追加。 #1 #8 #7 #9 #10
Browse files Browse the repository at this point in the history
  • Loading branch information
tsyu1234 committed Feb 20, 2024
1 parent ed4a0a3 commit edf6560
Show file tree
Hide file tree
Showing 12 changed files with 177 additions and 66 deletions.
13 changes: 13 additions & 0 deletions MAEasySimulator/Assets/BoxReady.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ GameObject:
serializedVersion: 6
m_Component:
- component: {fileID: 2240881192534159605}
- component: {fileID: -7524546012518654309}
m_Layer: 0
m_Name: BoxReady
m_TagString: Untagged
Expand All @@ -32,6 +33,18 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &-7524546012518654309
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1464484887366625871}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: cfd6265bad046554d9c8735a7d88d5cf, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &7628867827952849558
GameObject:
m_ObjectHideFlags: 0
Expand Down
6 changes: 5 additions & 1 deletion MAEasySimulator/Assets/DroneController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,15 @@ public class DroneController : MonoBehaviour {

void Start() {
Rbody = GetComponent<Rigidbody>();
Rbody.useGravity = false;
communicateArea.transform.localScale = new Vector3(communicationRange, communicationRange, communicationRange);
StartCoroutine(BatteryDrainCoroutine());
}

void OnTriggerEnter(Collider other) {
if (other.transform.parent != transform) { //子要素のコライダーは無視
return;
}
if (CrashTags.Contains(other.tag)) {
onCrash?.Invoke(other.transform.position);
FreeFall();
Expand Down Expand Up @@ -161,7 +165,7 @@ private IEnumerator BatteryDrainCoroutine() {
while (batteryLevel > 0) {
yield return new WaitForSeconds(1);
batteryLevel -= batteryDrainRate;
Debug.Log($"Battery Level: {batteryLevel}%");
//Debug.Log($"Battery Level: {batteryLevel}%");
}
onEmptyBattery?.Invoke();
FreeFall();
Expand Down
109 changes: 54 additions & 55 deletions MAEasySimulator/Assets/DroneStation.prefab
Original file line number Diff line number Diff line change
@@ -1,54 +1,87 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &2130525434300054539
--- !u!1 &2168808280500985780
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 6565329765527540276}
m_Layer: 0
m_Name: DroneStation
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &6565329765527540276
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2168808280500985780}
m_LocalRotation: {x: -0, y: -0.2916932, z: -0, w: 0.956512}
m_LocalPosition: {x: -254.95, y: 54.31, z: -9.51}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 1827038461486198216}
- {fileID: 6811473865920507492}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: -33.919, z: 0}
--- !u!1 &2701132897072582300
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 2911758439878901823}
- component: {fileID: 2219681077798126181}
- component: {fileID: 1362474665388504618}
- component: {fileID: 845946202842300339}
- component: {fileID: 6811473865920507492}
- component: {fileID: 2911556993101873366}
- component: {fileID: 6557095927663576692}
- component: {fileID: 4688787761085030820}
m_Layer: 0
m_Name: Plane
m_Name: Cube
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &2911758439878901823
--- !u!4 &6811473865920507492
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2130525434300054539}
m_GameObject: {fileID: 2701132897072582300}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0.9052, y: 0, z: -0}
m_LocalScale: {x: 1.9800127, y: 1, z: 1}
m_LocalPosition: {x: 5.5799, y: 0, z: -6.1911}
m_LocalScale: {x: 28.262371, y: 0.5, z: 13.3823395}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 6565329765527540276}
m_RootOrder: -1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!33 &2219681077798126181
--- !u!33 &2911556993101873366
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2130525434300054539}
m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0}
--- !u!23 &1362474665388504618
m_GameObject: {fileID: 2701132897072582300}
m_Mesh: {fileID: 10202, guid: 0000000000000000e000000000000000, type: 0}
--- !u!23 &6557095927663576692
MeshRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2130525434300054539}
m_GameObject: {fileID: 2701132897072582300}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
Expand Down Expand Up @@ -84,13 +117,13 @@ MeshRenderer:
m_SortingLayer: 0
m_SortingOrder: 0
m_AdditionalVertexStreams: {fileID: 0}
--- !u!64 &845946202842300339
MeshCollider:
--- !u!65 &4688787761085030820
BoxCollider:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2130525434300054539}
m_GameObject: {fileID: 2701132897072582300}
m_Material: {fileID: 0}
m_IncludeLayers:
serializedVersion: 2
Expand All @@ -102,43 +135,9 @@ MeshCollider:
m_IsTrigger: 0
m_ProvidesContacts: 0
m_Enabled: 1
serializedVersion: 5
m_Convex: 0
m_CookingOptions: 30
m_Mesh: {fileID: 10209, guid: 0000000000000000e000000000000000, type: 0}
--- !u!1 &2168808280500985780
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 6565329765527540276}
m_Layer: 0
m_Name: DroneStation
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &6565329765527540276
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2168808280500985780}
m_LocalRotation: {x: -0, y: -0.2916932, z: -0, w: 0.956512}
m_LocalPosition: {x: -254.95, y: 54.31, z: -9.51}
m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 2911758439878901823}
- {fileID: 1827038461486198216}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: -33.919, z: 0}
serializedVersion: 3
m_Size: {x: 1.0000004, y: 1, z: 1.0000004}
m_Center: {x: 0.00004577637, y: 0, z: 0.000009536741}
--- !u!1001 &1324234502382782488
PrefabInstance:
m_ObjectHideFlags: 0
Expand Down
4 changes: 2 additions & 2 deletions MAEasySimulator/Assets/Scenes/test0.4.unity
Git LFS file not shown
4 changes: 2 additions & 2 deletions MAEasySimulator/Assets/Shelter.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ BoxCollider:
m_ProvidesContacts: 0
m_Enabled: 1
serializedVersion: 3
m_Size: {x: 15, y: 10, z: 15}
m_Center: {x: 0, y: 5, z: 0}
m_Size: {x: 15, y: 5, z: 15}
m_Center: {x: 0, y: 3, z: 0}
--- !u!1001 &2317150450376699504
PrefabInstance:
m_ObjectHideFlags: 0
Expand Down
29 changes: 28 additions & 1 deletion MAEasySimulator/Assets/SpyAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@ public class SpyAgent : Agent {
private delegate void OnFindShelter(Vector3 pos);
private OnFindShelter _onFindShelter;
private string LogPrefix = "[Agent Spy]";
private Vector3 StartPosition;

void Start() {
_controller = GetComponent<DroneController>();
_env = GetComponentInParent<EnvManager>();
_controller.RegisterTeam(gameObject.tag);
_controller.AddCommunicateTarget(targetTag);
_controller.onCrash += OnCrash;
_controller.onEmptyBattery += OnEmpty;
Sensor = transform.Find("Sensor");
StartPosition = transform.localPosition;
}

public override void OnEpisodeBegin() {
Expand Down Expand Up @@ -58,7 +62,20 @@ public override void OnActionReceived(ActionBuffers actions) {
}

private void RewardDefinition() {

//1エピソード中に避難所を検出した回数に応じて報酬を与える
if (_findCount > 0) {
SetReward(0.1f * _findCount);
}
}

private void OnCrash(Vector3 position) {
Debug.Log(LogPrefix + "Crash at " + position);
EndEpisode();
}

private void OnEmpty() {
Debug.Log(LogPrefix + "Battery is empty");
//EndEpisode();
}

public override void Heuristic(in ActionBuffers actionsOut) {
Expand All @@ -77,6 +94,16 @@ private void _OnFindShelter(Vector3 pos) {
}


private void Reset() {
_findCount = 0;
transform.localPosition = StartPosition;
transform.localRotation = Quaternion.Euler(0, 0, 0);
_controller.batteryLevel = 100;
_controller.Rbody.useGravity = false;
_controller.Rbody.constraints = RigidbodyConstraints.FreezePosition | RigidbodyConstraints.FreezeRotation;
}





Expand Down
34 changes: 33 additions & 1 deletion MAEasySimulator/Assets/SpyAgent.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ GameObject:
- component: {fileID: 174229908787394523}
- component: {fileID: -646215098736134583}
- component: {fileID: 8559800387565644961}
- component: {fileID: -3061991587590451448}
m_Layer: 0
m_Name: SpyAgent
m_TagString: Spy
Expand Down Expand Up @@ -163,6 +164,7 @@ MonoBehaviour:
communicateArea: {fileID: 0}
CrashTags:
- Surpplier
- Obstacle
- Spy
Rbody: {fileID: 0}
CommunicateTargetTags:
Expand Down Expand Up @@ -255,6 +257,36 @@ Rigidbody:
m_Interpolate: 0
m_Constraints: 126
m_CollisionDetection: 0
--- !u!114 &-3061991587590451448
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6760585562241815342}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 6bb6b867a41448888c1cd4f99643ad71, type: 3}
m_Name:
m_EditorClassIdentifier:
m_SensorName: ObstractSensor
m_DetectableTags:
- Spy
- Surpplier
- Obstacle
m_RaysPerDirection: 3
m_MaxRayDegrees: 70
m_SphereCastRadius: 0.5
m_RayLength: 20
m_RayLayerMask:
serializedVersion: 2
m_Bits: 4294967291
m_ObservationStacks: 1
m_AlternatingRayOrder: 1
rayHitColor: {r: 1, g: 0, b: 0, a: 1}
rayMissColor: {r: 1, g: 1, b: 1, a: 1}
m_StartVerticalOffset: 0
m_EndVerticalOffset: 0
--- !u!1 &7326297137937280723
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -354,7 +386,7 @@ SphereCollider:
serializedVersion: 2
m_Bits: 0
m_LayerOverridePriority: 0
m_IsTrigger: 0
m_IsTrigger: 1
m_ProvidesContacts: 0
m_Enabled: 1
serializedVersion: 3
Expand Down
Loading

0 comments on commit edf6560

Please sign in to comment.