|
|
|
|
|
|
List<Agent> m_Agents = new List<Agent> { }; |
|
|
|
|
|
|
|
|
|
|
|
public BaseMultiAgentGroup() |
|
|
|
{ |
|
|
|
Academy.Instance.PostAgentAct += _GroupStep; |
|
|
|
} |
|
|
|
|
|
|
|
Academy.Instance.PostAgentAct -= _GroupStep; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
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(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
{ |
|
|
|
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(); |
|
|
|
} |
|
|
|
|
|
|
|
void Reset() |
|
|
|
{ |
|
|
|
m_StepCount = 0; |
|
|
|
} |
|
|
|
} |
|
|
|
} |