Ejemplo n.º 1
0
        public Plan MakePlan(
            World current, IGoal goal,
            RefreshActionsCallback actionRefresh, RefreshWorldCallback worldRefresh)
        {
            worldRefresh(current);
            PlanTree tree = new PlanTree(start: current);

            while (!tree.IsEmpty())
            {
                // Select the endpoint of the easiest plan we have
                // This is bredth-first, try "closest" for A*like
                PlanTree.Node n = tree.PopCheapestLeaf();

                if (goal.MeetsGoal(n.Expected))
                {
                    Debug.Log("Plan found!");
                    return(tree.GetPlan(n));
                }

                IList <Step> actions = actionRefresh(n.Expected);
                Debug.Log("Found " + actions.Count + " actions.");
                foreach (Step a in actions)
                {
                    tree.AddStep(n, a);
                }
            }

            Debug.Log("No plan exists!");
            return(new Plan(new List <Step>()));
        }
Ejemplo n.º 2
0
 public void DoPlanning()
 {
     // If we're currently planning, stop it.
     if (currentlyPlanning)
     {
         Debug.Log("Canceling current plan...");
         StopCoroutine("DoPlanningHelper");
         currentlyPlanning = false;
     }
     Debug.Log("Starting Planning . . .");
     // Update the things we can do
     RefreshPossibleActions();
     // Reset our planning tree
     tree = new PlanTree(world);
     // Store visited nodes in an unsorted list
     visited = new List <PlanTree.Node>();
     // Start a coroutine that looks at nodes every frame
     StartCoroutine(DoPlanningHelper());
 }