Example #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>()));
        }