AddReward(float Reward_) { if (GetNumChildNodes() > 0) { foreach (ArenaNode ChildNode_ in GetChildNodes()) { ChildNode_.AddReward(Reward_); } } else { if (gameObject.GetComponent <ArenaAgent>() != null) { gameObject.GetComponent <ArenaAgent>().AddReward(Reward_); } else { Debug.LogError("The very bottom ArenaNode should be attached with the ArenaAgent"); } } }
Kill(bool IsInternalKill_) { if (IsLiving()) { Living = false; // kill child nodes if (GetNumChildNodes() > 0) { foreach (ArenaNode ChildNode_ in GetChildNodes()) { ChildNode_.Kill(true); } IncrementChildKilledRanking(); } else { if (gameObject.GetComponent <ArenaAgent>() != null) { gameObject.GetComponent <ArenaAgent>().Kill(); } else { Debug.LogError("The very bottom ArenaNode should be attached with the ArenaAgent"); } } // record my ranking of being killed, then compute reward based on ranking if (GetParentNode() != null) { if (GetParentNode().IsRewardRanking) { // record my ranking of being killed SetKilledRanking(GetParentNode().GetChildKilledRanking()); } } if (IsRewardRanking) { // Debug.Log(GetLogTag() + " IsRewardRanking"); // detect if tie bool IsTie_ = true; int KilledRanking_ = -1; for (int i = 0; i < GetNumChildNodes(); i++) { if (i == 0) { KilledRanking_ = GetChildNodes()[i].GetKilledRanking(); } else { if (GetChildNodes()[i].GetKilledRanking() != KilledRanking_) { IsTie_ = false; break; } } } // penalize tie if (IsTie_) { // Debug.Log(GetLogTag() + " Tie"); // penalize tie if (IsPenalizeTie) { foreach (ArenaNode ChildNode_ in GetChildNodes()) { // add the computed reward ChildNode_.AddReward( -1f * globalManager.RewardRankingCoefficient * RewardSchemeScale); } } } else { // reward based on ranking foreach (ArenaNode ChildNode_ in GetChildNodes()) { RewardRanking(this, ChildNode_); } } } // notice parent node that a child has been killed if (GetParentNode() != null) { if (!IsInternalKill_) { if (GetParentNode().IsRewardRanking) { GetParentNode().IncrementChildKilledRanking(); } GetParentNode().OnChildNodeKilled(); } } else { gameObject.GetComponent <GlobalManager>().Done(); } } } // Kill