浏览代码

add team reward

/develop/cc-teammanager
Ruo-Ping Dong 4 年前
当前提交
7303985e
共有 4 个文件被更改,包括 51 次插入15 次删除
  1. 1
      Project/Assets/ML-Agents/Examples/Hallway/TFModels/HallwayCollab.onnx.meta
  2. 36
      Project/Assets/ML-Agents/Examples/PushBlock/Scripts/PushBlockTeamManager.cs
  3. 28
      Project/Assets/ML-Agents/Examples/PushBlock/Scripts/ZombiePushBlockDeathEnvController.cs
  4. 1
      com.unity.ml-agents/Runtime/Agent.cs

1
Project/Assets/ML-Agents/Examples/Hallway/TFModels/HallwayCollab.onnx.meta


fileIDToRecycleName:
11400000: main obj
11400002: model data
2186277476908879412: ImportLogs
externalObjects: {}
userData:
assetBundleName:

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


public class PushBlockTeamManager : BaseTeamManager
{
List<Agent> m_AgentList = new List<Agent> { };
Dictionary<Agent, bool> m_AgentDoneState = new Dictionary<Agent, bool> { };
m_AgentList.Add(agent);
m_AgentDoneState[agent] = false;
}
public override void OnAgentDone(Agent agent, Agent.DoneReason doneReason, List<ISensor> sensors)
{
m_AgentDoneState[agent] = true;
if (!m_AgentDoneState.ContainsValue(false))
{
foreach (var doneAgent in m_AgentDoneState.Keys)
{
doneAgent.SendDoneToTrainer();
}
}
}
public void ResetAgent(Agent agent)
{
if (!m_AgentDoneState.ContainsKey(agent))
{
RegisterAgent(agent);
}
else
{
m_AgentDoneState[agent] = false;
}
}
public override void AddTeamReward(float reward)
{
foreach (var agent in m_AgentDoneState.Keys)
{
agent.AddReward(reward);
}
}
}

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


// col.gameObject.SetActive(false);
//Give Agent Rewards
foreach (var item in AgentsList)
{
if (item.Agent.gameObject.activeInHierarchy)
{
print($"{item.Agent.name} scored");
item.Agent.AddReward(score);
}
}
// foreach (var item in AgentsList)
// {
// if (item.Agent.gameObject.activeInHierarchy)
// {
// print($"{item.Agent.name} scored");
// item.Agent.AddReward(score);
// }
// }
m_TeamManager.AddTeamReward(score);
// Swap ground material for a bit to indicate we scored.
StartCoroutine(GoalScoredSwapGroundMaterial(m_PushBlockSettings.goalScoredMaterial, 0.5f));

public void ZombieTouchedBlock()
{
//Give Agent Rewards
foreach (var item in AgentsList)
{
item.Agent.AddReward(-1);
}
// foreach (var item in AgentsList)
// {
// item.Agent.AddReward(-1);
// }
m_TeamManager.AddTeamReward(-1);
// Swap ground material for a bit to indicate we scored.
StartCoroutine(GoalScoredSwapGroundMaterial(m_PushBlockSettings.failMaterial, 0.5f));
ResetScene();

item.Rb.velocity = Vector3.zero;
item.Rb.angularVelocity = Vector3.zero;
item.Agent.gameObject.SetActive(true);
m_TeamManager.ResetAgent(item.Agent);
}
//Reset Blocks

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


public void SendDoneToTrainer()
{
m_Info.reward = m_Reward;
// We request a decision so Python knows the Agent is done immediately
m_Brain?.RequestDecision(m_Info, sensors);
ResetSensors();

正在加载...
取消
保存