浏览代码

add reward discount

/develop/teammanager
Ruo-Ping Dong 4 年前
当前提交
cbb4c7c8
共有 3 个文件被更改,包括 24 次插入10 次删除
  1. 2
      Project/Assets/ML-Agents/Examples/PushBlock/Prefabs/ZombiePushBlockDeathCollabArea.prefab
  2. 28
      Project/Assets/ML-Agents/Examples/PushBlock/Scripts/PushBlockTeamManager.cs
  3. 4
      Project/Assets/ML-Agents/Examples/PushBlock/Scripts/ZombiePushBlockDeathEnvController.cs

2
Project/Assets/ML-Agents/Examples/PushBlock/Prefabs/ZombiePushBlockDeathCollabArea.prefab


UseRandomBlockRotation: 1
UseRandomBlockPosition: 1
UseTeamManager: 1
UseTeamReward: 1
TeamRewardDiscount: 0.995
--- !u!1 &4478780967772121042
GameObject:
m_ObjectHideFlags: 0

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


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

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

}
public void SetRewardDiscount(float discountRate)
{
m_RewardDiscount = discountRate;
}
}

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


public bool UseRandomBlockPosition = true;
public bool UseTeamManager = true;
public bool UseTeamReward = true;
// public bool DiscountTeamReward = true;
public float TeamRewardDiscount = 1;
PushBlockSettings m_PushBlockSettings;
private BaseTeamManager m_TeamManager;

if (UseTeamReward)
{
m_TeamManager = new PushBlockTeamManager();
var pushManager = (PushBlockTeamManager)m_TeamManager;
pushManager.SetRewardDiscount(TeamRewardDiscount);
}
else
{

正在加载...
取消
保存