|
|
|
|
|
|
List<Agent> m_Agents = new List<Agent> { }; |
|
|
|
|
|
|
|
|
|
|
|
public BaseMultiAgentGroup() |
|
|
|
{ |
|
|
|
Academy.Instance.PostAgentAct += _GroupStep; |
|
|
|
} |
|
|
|
|
|
|
|
Academy.Instance.PostAgentAct -= _GroupStep; |
|
|
|
while (m_Agents.Count > 0) |
|
|
|
{ |
|
|
|
UnregisterAgent(m_Agents[0]); |
|
|
|
|
|
|
void _GroupStep() |
|
|
|
{ |
|
|
|
m_StepCount += 1; |
|
|
|
if ((m_StepCount >= m_GroupMaxStep) && (m_GroupMaxStep > 0)) |
|
|
|
{ |
|
|
|
foreach (var agent in m_Agents) |
|
|
|
{ |
|
|
|
if (agent.enabled) |
|
|
|
{ |
|
|
|
agent.EpisodeInterrupted(); |
|
|
|
} |
|
|
|
} |
|
|
|
Reset(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Register the agent to the MultiAgentGroup.
|
|
|
|
/// Registered agents will be able to receive group rewards from the MultiAgentGroup
|
|
|
|
|
|
|
{ |
|
|
|
foreach (var agent in m_Agents) |
|
|
|
{ |
|
|
|
if (agent.enabled) |
|
|
|
{ |
|
|
|
agent.AddGroupReward(reward); |
|
|
|
} |
|
|
|
agent.AddGroupReward(reward); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
{ |
|
|
|
foreach (var agent in m_Agents) |
|
|
|
{ |
|
|
|
if (agent.enabled) |
|
|
|
{ |
|
|
|
agent.SetGroupReward(reward); |
|
|
|
} |
|
|
|
agent.SetGroupReward(reward); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
/// <returns>
|
|
|
|
/// Current step count.
|
|
|
|
/// </returns>
|
|
|
|
public int StepCount |
|
|
|
public void EndGroupEpisode() |
|
|
|
get { return m_StepCount; } |
|
|
|
} |
|
|
|
|
|
|
|
public int GroupMaxStep |
|
|
|
{ |
|
|
|
get { return m_GroupMaxStep; } |
|
|
|
} |
|
|
|
|
|
|
|
public void SetGroupMaxStep(int maxStep) |
|
|
|
{ |
|
|
|
m_GroupMaxStep = maxStep; |
|
|
|
foreach (var agent in m_Agents) |
|
|
|
{ |
|
|
|
agent.EndEpisode(); |
|
|
|
} |
|
|
|
public void EndGroupEpisode() |
|
|
|
public void GroupEpisodeInterrupted() |
|
|
|
if (agent.enabled) |
|
|
|
{ |
|
|
|
agent.EndEpisode(); |
|
|
|
} |
|
|
|
agent.EpisodeInterrupted(); |
|
|
|
Reset(); |
|
|
|
} |
|
|
|
|
|
|
|
public virtual void OnGroupEpisodeBegin() |
|
|
|
{ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
void Reset() |
|
|
|
{ |
|
|
|
m_StepCount = 0; |
|
|
|
OnGroupEpisodeBegin(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |