Ejemplo n.º 1
0
        /// <summary>
        /// If the planner and action queue are null, find and start a new plan.
        /// </summary>
        private void FindNewPlan()
        {
            // ------- CHECK IF THE PLANNER OR ACTION QUEUE ARE NULL --------

            if (planner == null || actionQueue == null)
            {
                // -------------------- CREATE A NEW PLANNER --------------------

                planner = new GPlanner();
                target  = null;

                // --------------- SORT GOALS IN DESCENDING ORDER ---------------

                var sortedGoals = SortGoals();

                // ---------------------- FIND A NEW PLAN -----------------------

                foreach (KeyValuePair <SubGoal, int> sg in sortedGoals)
                {
                    actionQueue = planner.Plan(actions, sg.Key.sGoals, beliefs);
                    if (actionQueue != null)
                    {
                        ActionList = new List <GAction>(actionQueue);
                    }

                    // ------------------ CHECK IF WE FOUND A PLAN ------------------

                    if (actionQueue != null)
                    {
                        currentGoal = sg.Key; // Set the current goal
                        break;                // Goal is found, break out of the loop
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void ChangePriority(State g, int newPriority)
        {
            SubGoal key = goals.Keys.Single(x => x.goalName == g);

            if (key != null)
            {
                goals[key] = newPriority;
            }

            if (currentAction != null && currentAction.GoalPriorityChange)
            {
                ForceNewPlan();
            }
        }