Beispiel #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
                    }
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Checks if action queue is empty and both: 1) removes sub-goal (if applicable) 2) sets planner to null, so a new plan is created.
        /// </summary>
        private void CheckForEmptyActionQueue()
        {
            // ------------- HAS AN EMPTY ACTION QUEUE --------------

            if (actionQueue != null && actionQueue.Count == 0)
            {
                // ----- CHECK IF ACTION IS REMOVABLE AND REMOVE IT -----

                if (currentGoal.remove)
                {
                    goals.Remove(currentGoal);
                }

                // ----------- TRIGGER A NEW PLAN NEXT UPDATE -----------

                planner = null;
            }
        }
Beispiel #3
0
 /// <summary>
 /// Forces a new plan, regardless of the status of the current action.
 /// </summary>
 public void ForceNewPlan()
 {
     isRunningAction = false;
     actionQueue     = null;
     planner         = null;
 }