Exemple #1
0
 public void ExecutePlan(Queue <AIAction> newActionPlan, AIGoal goal)
 {
     if (currentAction != null)
     {
         stateMachine.Stop();
         stateMachine.Activate();    // TODO.. stop activate should be simpler
     }
     currentGoal = goal;
     actionPlan  = newActionPlan;
     BeginNextAction();
 }
Exemple #2
0
        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));
        }
Exemple #3
0
        public void CalculateNewGoal()
        {
            AILogger.CreateMessage("Calculating new goal.", agent);

            List <AIGoal> goals = new List <AIGoal>(agent.GetGoals());

            goals.Sort((x, y) => x.Priority.CompareTo(y.Priority));

            if (goals.Count == 0)
            {
                return;
            }

            for (int i = 0; i < goals.Count; i++)
            {
                currentGoal = goals[i];
                if (!GoalAchieveableByActions(currentGoal))
                {
                    continue;
                }

                if (aStar.FindActionPlan(agent, this))
                {
                    actions = aStar.GetActionPlan();
                }
                else
                {
                    AILogger.CreateMessage("failed to find action plan.", agent);
                }
            }

            if (actions.Count > 0 && OnActionPlanFound != null)
            {
                OnActionPlanFound();
            }
        }