GetNumLivingChildNodes() { if (GetNumChildNodes() > 0) { int NumLivingNodes_ = 0; foreach (ArenaNode ChildNode_ in GetChildNodes()) { if (ChildNode_.IsLiving()) { NumLivingNodes_++; } } return(NumLivingNodes_); } else { if (gameObject.GetComponent <ArenaAgent>() != null) { Debug.LogError( "GetNumLivingChildNodes() should not be called at bottom level, i.e., the same level as ArenaAgent."); return(-1); } else { Debug.LogError("The very bottom ArenaNode should be attached with the ArenaAgent"); return(-1); } } }
Step() { CheckNumChildNodes(); StepUtils(); StepRewardFunction(); if (GetNumChildNodes() > 0) { foreach (ArenaNode ChildNode_ in GetChildNodes()) { ChildNode_.Step(); } } else { if (gameObject.GetComponent <ArenaAgent>() != null) { } else { Debug.LogError("The very bottom ArenaNode should be attached with the ArenaAgent"); } } if (MaxNumLivingSteps > 0) { if (NumLivingSteps >= (MaxNumLivingSteps - 1)) { Kill(); } } NumLivingSteps++; }
Reset() { CheckNumChildNodes(); NumLivingSteps = 0; Living = true; ResetUtils(); ResetRewardFunctions(); ResetChildKilledRanking(); if (GetNumChildNodes() > 0) { foreach (ArenaNode ChildNode_ in GetChildNodes()) { ChildNode_.Reset(); } } else { if (gameObject.GetComponent <ArenaAgent>() != null) { return; } else { Debug.LogError("The very bottom ArenaNode should be attached with the ArenaAgent"); } } }
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"); } } }
IncrementAttribute(string Key_, float IncrementValue_) { if (GetNumChildNodes() > 0) { foreach (ArenaNode ChildNode_ in GetChildNodes()) { ChildNode_.IncrementAttribute(Key_, IncrementValue_); } } else { if (gameObject.GetComponent <ArenaAgent>() != null) { gameObject.GetComponent <ArenaAgent>().IncrementAttribute(Key_, IncrementValue_); } 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