浏览代码

add discount for team reward

/develop/cc-teammanager
Ruo-Ping Dong 4 年前
当前提交
55e71779
共有 3 个文件被更改,包括 26 次插入1008 次删除
  1. 998
      Project/Assets/ML-Agents/Examples/PushBlock/Scenes/2ZombieVs3AgentsPushBlock.unity
  2. 33
      Project/Assets/ML-Agents/Examples/PushBlock/Scripts/PushBlockTeamManager.cs
  3. 3
      Project/Assets/ML-Agents/Examples/PushBlock/Scripts/ZombiePushBlockDeathEnvController.cs

998
Project/Assets/ML-Agents/Examples/PushBlock/Scenes/2ZombieVs3AgentsPushBlock.unity
文件差异内容过多而无法显示
查看文件

33
Project/Assets/ML-Agents/Examples/PushBlock/Scripts/PushBlockTeamManager.cs


using UnityEngine;
using Unity.MLAgents.Extensions.Teams;
using Unity.MLAgents.Sensors;
using System;
Dictionary<Agent, bool> m_AgentDoneState = new Dictionary<Agent, bool> { };
float m_rewardDiscount = 1;
// -1 means not done
Dictionary<Agent, int> m_AgentDoneStep = new Dictionary<Agent, int> { };
Dictionary<Agent, float> m_AgentRewardDiscount = new Dictionary<Agent, float> { };
public PushBlockTeamManager()
{
}
public PushBlockTeamManager(float rewardDiscount)
{
m_rewardDiscount = rewardDiscount;
}
m_AgentDoneState[agent] = false;
m_AgentDoneStep[agent] = -1;
m_AgentDoneState[agent] = true;
m_AgentDoneStep[agent] = agent.StepCount;
foreach (var agent in m_AgentDoneState.Keys.ToList())
foreach (var agent in m_AgentDoneStep.Keys.ToList())
if (m_AgentDoneState[agent])
if (m_AgentDoneStep[agent] >= 0)
m_AgentDoneState[agent] = false;
m_AgentDoneStep[agent] = -1;
}
}
}

foreach (var agent in m_AgentDoneState.Keys)
int maxAgentStep = m_AgentDoneStep.Values.Max();
foreach (var agent in m_AgentDoneStep.Keys)
if (m_AgentDoneState[agent])
if (m_AgentDoneStep[agent] >= 0)
agent.AddRewardAfterDeath(reward);
agent.AddRewardAfterDeath(reward * (float)Math.Pow(m_rewardDiscount, maxAgentStep - m_AgentDoneStep[agent]));
}
else
{

3
Project/Assets/ML-Agents/Examples/PushBlock/Scripts/ZombiePushBlockDeathEnvController.cs


public bool UseRandomBlockPosition = true;
public bool UseTeamManager = true;
public bool UseTeamReward = true;
public float TeamRewardDiscountRate = 1;
PushBlockSettings m_PushBlockSettings;
private int m_NumberOfRemainingBlocks;

{
if (UseTeamReward)
{
m_TeamManager = new PushBlockTeamManager();
m_TeamManager = new PushBlockTeamManager(TeamRewardDiscountRate);
}
else
{

正在加载...
取消
保存