浏览代码

team manager for hallway

/develop/centralizedcritic/counterfact
Ruo-Ping Dong 4 年前
当前提交
ef054af0
共有 3 个文件被更改,包括 31 次插入8 次删除
  1. 15
      com.unity.ml-agents.extensions/Runtime/Teams/BaseTeamManager.cs
  2. 22
      com.unity.ml-agents/Runtime/Agent.cs
  3. 2
      com.unity.ml-agents/Runtime/ITeamManager.cs

15
com.unity.ml-agents.extensions/Runtime/Teams/BaseTeamManager.cs


using Unity.MLAgents;
using Unity.MLAgents.Sensors;
namespace Teams
namespace Unity.MLAgents.Extensions.Teams
// TODO abstract? inherit from MonoBehavior?
public void RegisterAgent(Agent agent)
string m_Id = System.Guid.NewGuid().ToString();
public virtual void RegisterAgent(Agent agent)
public void OnAgentDone(Agent agent, Agent.DoneReason doneReason, List<ISensor> sensors)
public virtual void OnAgentDone(Agent agent, Agent.DoneReason doneReason, List<ISensor> sensors)
{
// Possible implementation - save reference to Agent's IPolicy so that we can repeatedly
// call IPolicy.RequestDecision on behalf of the Agent after it's dead

public void AddTeamReward(float reward)
public virtual void AddTeamReward(float reward)
}
public string GetId()
{
return m_Id;
}
}

22
com.unity.ml-agents/Runtime/Agent.cs


/// </summary>
public int episodeId;
/// <summary>
/// Team Manager identifier.
/// </summary>
public string teamManagerId;
public void ClearActions()
{
storedVectorActions.Clear();

new int[m_ActuatorManager.NumDiscreteActions]
);
if (m_TeamManager != null)
{
m_Info.teamManagerId = m_TeamManager.GetId();
}
// The first time the Academy resets, all Agents in the scene will be
// forced to reset through the <see cref="AgentForceReset"/> event.
// To avoid the Agent resetting twice, the Agents will not begin their

}
else
{
// We request a decision so Python knows the Agent is done immediately
m_Brain?.RequestDecision(m_Info, sensors);
ResetSensors();
SendDoneToTrainer();
ResetSensors();
// We also have to write any to any DemonstationStores so that they get the "done" flag.
foreach (var demoWriter in DemonstrationWriters)

m_RequestAction = false;
m_RequestDecision = false;
m_Info.storedVectorActions.Clear();
}
public void SendDoneToTrainer()
{
// We request a decision so Python knows the Agent is done immediately
m_Brain?.RequestDecision(m_Info, sensors);
}
/// <summary>

public void SetTeamManager(ITeamManager teamManager)
{
m_TeamManager = teamManager;
m_Info.teamManagerId = teamManager?.GetId();
teamManager?.RegisterAgent(this);
}
}

2
com.unity.ml-agents/Runtime/ITeamManager.cs


{
public interface ITeamManager
{
string GetId();
void RegisterAgent(Agent agent);
// TODO not sure this is all the info we need, maybe pass a class/struct instead.
void OnAgentDone(Agent agent, Agent.DoneReason doneReason, List<ISensor> sensors);
正在加载...
取消
保存