UtilityObject GetMaxScoreUtilityObject(UtilityObject[] utilityObjects) { UtilityObject maxUtilityObject = null; // find goal with the highest utility (need/desire/motive) float maxUtility = 0; UtilityAgentGoal maxGoal = null; foreach (var goal in goals) { if (goal.utility > maxUtility) { maxUtility = goal.utility; maxGoal = goal; } } // get the utility object with the highest score for the goal if (maxUtility > utilityThreshold) { float maxScore = 0; foreach (var utilityObject in utilityObjects) { float score = utilityObject.GetScore(maxGoal.id); if (score > maxScore) { maxScore = score; maxUtilityObject = utilityObject; } } } return(maxUtilityObject); }
void UpdateUtilityObjectScore(UtilityObject utilityObject) { foreach (var goal in goals) { float score = utilityObject.GetScore(goal.id); goal.input += score; } }