public void Decide() { // Calculate the sqr to compare to the dot product float nearSqr = near * near; List <AttributeValue> values = new List <AttributeValue>(); foreach (var need in needs) { var dist = need.target.transform.position - character.transform.position; // If the need is selected we simple state whether its Near or Far // If it isn't selected we simply state "No" values.Add(new AttributeValue(need.inputName, need.toggle.isOn ? ((dist.sqrMagnitude > nearSqr) ? "Far" : "Near") : "No")); } // Now we use the decision tree to see which of the needs we need to satisfy first // o In human reasoning thirst and hunger will always take precedence over other needs // o The distance to satisfy the need is also a factor // o Please note that in a game context these needs would have their own // mecanisms such as using energy depletion as an indication of hunger. DecisionQuery query = new DecisionQuery(); bool decided = false; StringBuilder builder = new StringBuilder(); foreach (var need in needs) { if (!need.toggle.isOn) { continue; } query.Set(treeName, need.inputName, values.ToArray()); tree.Decide(query); if (query.Yes) { character.target = need.target; decided = true; } builder.AppendLine(tree.PrintDecision(query)); } // Print the last query text.text = builder.ToString(); if (!decided) { character.target = startPoint; } }
public bool?Decide(DecisionQuery query) { return(decisionTree.Decide(query)); }