private void ActionSuccess() { foreach (var effect in currentAction.GetEffects()) { agent.GetMemory().UpdateCondition(effect.Key, effect.Value); } bool goalAchieved = true; foreach (var condition in currentGoal.GetConditions()) { if (agent.GetMemory().ConditionMet(condition.Key, condition.Value) == false) { goalAchieved = false; break; } } if (goalAchieved) { Stop(); if (OnFinishedPlan != null) { OnFinishedPlan(); } } else { BeginNextAction(); } }
private bool GoalAchieveableByActions(AIGoal goal) { // Note that this won't check if each action's preconditions will be met. // This will be calculated by aStar Dictionary <string, bool> conditionsMet = new Dictionary <string, bool>(); foreach (var condition in goal.GetConditions()) { conditionsMet.Add(condition.Key, false); } foreach (var stateValue in agent.GetMemory().GetState()) { if (conditionsMet.ContainsKey(stateValue.Key) && conditionsMet[stateValue.Key].Equals(goal.GetConditions()[stateValue.Key])) { conditionsMet[stateValue.Key] = true; } } foreach (var action in agent.GetActions()) { if (!action.CheckProceduralPrecondition()) { continue; } foreach (var effect in action.GetEffects()) { if (conditionsMet.ContainsKey(effect.Key) && effect.Value.Equals(goal.GetConditions()[effect.Key])) { conditionsMet[effect.Key] = true; } } } return(!conditionsMet.ContainsValue(false)); }