public static void ApplyAndValidatePlan(IReGoapGoal <string, object> plan, ReGoapTestMemory memory) { foreach (var action in plan.GetPlan()) { Assert.That(action.Action.GetPreconditions(plan.GetGoalState()).MissingDifference(memory.GetWorldState(), 1) == 0); foreach (var effectsPair in action.Action.GetEffects(plan.GetGoalState()).GetValues()) { // in a real game this should be done by memory itself // e.x. isNearTarget = (transform.position - target.position).magnitude < minRangeForCC string key = effectsPair.Key; StructValue curValue; StructValue endValue; if (memory.GetWorldState().GetValues().TryGetValue(key, out curValue)) { endValue = curValue.MergeWith(effectsPair.Value); } else { endValue = effectsPair.Value; } memory.SetStructValue(effectsPair.Key, endValue); } } Assert.That(plan.GetGoalState().MissingDifference(memory.GetWorldState(), 1) == 0); }
public static void ApplyAndValidatePlan(IReGoapGoal plan, ReGoapTestMemory memory) { foreach (var action in plan.GetPlan()) { Assert.That(action.Action.GetPreconditions(plan.GetGoalState()).MissingDifference(memory.GetWorldState(), 1) == 0); foreach (var effectsPair in action.Action.GetEffects(plan.GetGoalState()).GetValues()) { // in a real game this should be done by memory itself // e.x. isNearTarget = (transform.position - target.position).magnitude < minRangeForCC memory.SetValue(effectsPair.Key, effectsPair.Value); } } Assert.That(plan.GetGoalState().MissingDifference(memory.GetWorldState(), 1) == 0); }
public static void ApplyAndValidatePlan(IReGoapGoal <string, object> plan, ReGoapTestAgent agent, ReGoapTestMemory memory) { GoapActionStackData <string, object> stackData; stackData.agent = agent; stackData.currentState = memory.GetWorldState(); stackData.goalState = plan.GetGoalState(); stackData.next = null; stackData.settings = null; foreach (var action in plan.GetPlan()) { stackData.settings = action.Settings; Assert.That(action.Action.GetPreconditions(stackData).MissingDifference(stackData.currentState, 1) == 0); foreach (var effectsPair in action.Action.GetEffects(stackData).GetValues()) { // in a real game this should be done by memory itself // e.x. isNearTarget = (transform.position - target.position).magnitude < minRangeForCC memory.SetValue(effectsPair.Key, effectsPair.Value); } } Assert.That(plan.GetGoalState().MissingDifference(memory.GetWorldState(), 1) == 0); }