-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
【マルチエージェント化】環境全体の操作とグループの報酬を担当するEnvControllerを追加。
- Loading branch information
Showing
22 changed files
with
535 additions
and
323 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
using Unity.MLAgents; | ||
using Unity.MLAgents.Sensors; | ||
using Unity.MLAgents.Actuators; | ||
|
||
public class EnvController : MonoBehaviour | ||
{ | ||
private DorokSettings m_DorokSettings; | ||
|
||
[System.Serializable] | ||
public class PlayerInfo { | ||
public DorokAgent Agent; | ||
[HideInInspector] | ||
public Vector3 StartingPos; | ||
[HideInInspector] | ||
public Quaternion StartingRot; | ||
[HideInInspector] | ||
public Rigidbody Rb; | ||
} | ||
|
||
|
||
/*警察グループ*/ | ||
public SimpleMultiAgentGroup PoliceGroup; | ||
/*逃走者グループ*/ | ||
public SimpleMultiAgentGroup CriminerGroup; | ||
|
||
|
||
//List of Agents On Platform | ||
public List<PlayerInfo> AgentsList = new List<PlayerInfo>(); | ||
|
||
private int m_ResetTimer; | ||
|
||
[Tooltip("Max Environment Steps")] public int MaxEnvironmentSteps = 25000; | ||
|
||
void Start() { | ||
var PoliceCount = 0; | ||
var CriminerCount = 0; | ||
m_DorokSettings = FindObjectOfType<DorokSettings>(); | ||
// Initialize TeamManager | ||
PoliceGroup = new SimpleMultiAgentGroup(); | ||
CriminerGroup = new SimpleMultiAgentGroup(); | ||
print("AgentsList Count: "); | ||
print(AgentsList); | ||
foreach (var item in AgentsList) { | ||
if (item.Agent.team == Team.Police) { | ||
PoliceGroup.RegisterAgent(item.Agent); | ||
PoliceCount++; | ||
} else { | ||
CriminerGroup.RegisterAgent(item.Agent); | ||
CriminerCount++; | ||
} | ||
} | ||
print("TeamManager Initialized"); | ||
print("PoliceGroup: " + PoliceCount + " Agents"); | ||
print("CriminerGroup: " + CriminerCount + " Agents"); | ||
} | ||
|
||
|
||
void FixedUpdate() { | ||
m_ResetTimer += 1; | ||
if (m_ResetTimer >= MaxEnvironmentSteps && MaxEnvironmentSteps > 0) { | ||
PoliceGroup.GroupEpisodeInterrupted(); | ||
CriminerGroup.GroupEpisodeInterrupted(); | ||
ResetScene(); | ||
} | ||
} | ||
|
||
/** | ||
1マッチ終了時の報酬処理 | ||
(逃走者が全員捕まるか、制限時間切れの場合) | ||
*/ | ||
public void MatchEnd(Team team) { | ||
if (team == Team.Police) { | ||
PoliceGroup.AddGroupReward(1); | ||
CriminerGroup.AddGroupReward(-1); | ||
} else { | ||
PoliceGroup.AddGroupReward(-1); | ||
CriminerGroup.AddGroupReward(1); | ||
} | ||
|
||
PoliceGroup.GroupEpisodeInterrupted(); | ||
CriminerGroup.GroupEpisodeInterrupted(); | ||
ResetScene(); | ||
} | ||
|
||
|
||
public void ResetScene() { | ||
m_ResetTimer = 0; | ||
|
||
//Reset Agents | ||
foreach (var item in AgentsList) { | ||
var randomPosX = Random.Range(-5f, 5f); | ||
var newStartPos = item.Agent.initialPos + new Vector3(randomPosX, 0f, 0f); | ||
var rot = item.Agent.rotSign * Random.Range(80.0f, 100.0f); | ||
var newRot = Quaternion.Euler(0, rot, 0); | ||
item.Agent.transform.SetPositionAndRotation(newStartPos, newRot); | ||
|
||
item.Rb.velocity = Vector3.zero; | ||
item.Rb.angularVelocity = Vector3.zero; | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
1on1FlagGame/1on1DoroK-MLTEST1/Assets/EnvController.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
1on1FlagGame/1on1DoroK-MLTEST1/Assets/ML-Agents/Timers/Dorok_timers.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"count":1,"self":118.0938496,"total":118.09881689999999,"children":{"InitializeActuators":{"count":1,"self":0.001967,"total":0.001967,"children":null},"InitializeSensors":{"count":1,"self":0.0019974999999999997,"total":0.0019974999999999997,"children":null}},"gauges":{},"metadata":{"timer_format_version":"0.1.0","start_time_seconds":"1671984344","unity_version":"2021.3.14f1","command_line_arguments":"F:\\Program Files\\Unity\\2021.3.14f1\\Editor\\Unity.exe -projectpath F:\\Products\\GraduateReport2\\1on1FlagGame\\1on1DoroK-MLTEST1 -useHub -hubIPC -cloudEnvironment production","communication_protocol_version":"1.5.0","com.unity.ml-agents_version":"2.3.0-exp.3","scene_name":"Dorok","end_time_seconds":"1671984462"}} | ||
{"count":1,"self":27.4244192,"total":27.4354715,"children":{"InitializeActuators":{"count":2,"self":0.0009969,"total":0.0009969,"children":null},"InitializeSensors":{"count":2,"self":0.0019944,"total":0.0019944,"children":null},"AgentSendState":{"count":1,"self":0.0040199,"total":0.0060907,"children":{"CollectObservations":{"count":1,"self":0,"total":0,"children":null},"WriteActionMask":{"count":1,"self":0,"total":0,"children":null},"RequestDecision":{"count":1,"self":0.0020708,"total":0.0020708,"children":{"RayPerceptionSensor.Perceive":{"count":1,"self":0,"total":0,"children":null}}}}},"DecideAction":{"count":1,"self":0.00094409999999999991,"total":0.00094409999999999991,"children":null},"AgentAct":{"count":1,"self":0,"total":0,"children":null}},"gauges":{},"metadata":{"timer_format_version":"0.1.0","start_time_seconds":"1672032004","unity_version":"2021.3.14f1","command_line_arguments":"F:\\Program Files\\Unity\\2021.3.14f1\\Editor\\Unity.exe -projectpath F:\\Products\\GraduateReport2\\1on1FlagGame\\1on1DoroK-MLTEST1 -useHub -hubIPC -cloudEnvironment production","communication_protocol_version":"1.5.0","com.unity.ml-agents_version":"2.3.0-exp.3","scene_name":"Dorok","end_time_seconds":"1672032031"}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
Oops, something went wrong.