public ActionCallback Process(VariableCollection globalVars, VariableCollection agentProfile) { // Fetch value float val; if (agentProfile.HasVar(var)) { val = agentProfile.GetVar(var); } else { val = globalVars.GetVar(var); } // Find value to make decision based off foreach (Range range in ranges) { if (useGreaterThan ? val > range.max : val < range.max) { return(range.decision != null?range.decision.Process(globalVars, agentProfile) : null); } } return(defaultDecision != null?defaultDecision.Process(globalVars, agentProfile) : null); }
/// <summary> /// Run through the tree and update the current action /// </summary> public void Recalculate() { currentAction = rootDecision != null?rootDecision.Process(globalVars, agentProfile) : null; currentActionName = "None"; foreach (var pair in actionStates) { if (pair.Value == currentAction) { currentActionName = pair.Key; break; } } }
public ActionCallback Process(VariableCollection globalVars, VariableCollection agentProfile) { // Fetch value float valA, valB; if (agentProfile.HasVar(varA)) { valA = agentProfile.GetVar(varA); } else { valA = globalVars.GetVar(varA); } if (agentProfile.HasVar(varB)) { valB = agentProfile.GetVar(varB); } else { valB = globalVars.GetVar(varB); } // Calculate condition bool condition = false; switch (operand) { case Operand.Equals: condition = (valA == valB); break; case Operand.NotEquals: condition = (valA != valB); break; case Operand.GreaterThan: condition = (valA > valB); break; case Operand.GreaterThanEquals: condition = (valA >= valB); break; case Operand.LessThan: condition = (valA < valB); break; case Operand.LessThanEquals: condition = (valA <= valB); break; } if (condition) { return(trueDecision != null?trueDecision.Process(globalVars, agentProfile) : null); } else { return(falseDecision != null?falseDecision.Process(globalVars, agentProfile) : null); } }