Exemple #1
0
    public bool MeetsAdditionalPreconditions(WorldState mWorldState, PlanningAction action)
    {
        bool    meets         = false;
        bool    changePos     = false;
        Vector3 ingredientPos = new Vector3();

        switch (action.mActionType)
        {
        case PlanningAction.ActionType.AT_GO_TO:
            meets = ValidIngredient(mWorldState, action.mIngredient) && GetIngredientOfType(action.mIngredient) != null;
            break;

        case PlanningAction.ActionType.AT_PICK_UP:
            ingredientPos = FindIngredientOfType(action.mIngredient);
            //Check if you already have the ingredient to not go again for it
            if (!mWorldState.ingredientsKept.Contains(action.mIngredient))
            {
                changePos = true;
            }
            break;

        case PlanningAction.ActionType.AT_GO_TO_KITCHEN:
            meets = RecipeCompleted(mWorldState) != null ? true : false;
            break;

        default:
            meets = true;
            break;
        }
        if (changePos)
        {
            meets = (ingredientPos - mWorldState.cPos).magnitude <= 2 ? true : false;
        }
        return(meets);
    }
Exemple #2
0
    /***************************************************************************/

    public NodePlanning(WorldState worldState, PlanningAction action)
    {
        mWorldState = new WorldState(worldState);
        mAction     = action;

        gCost   = 0.0f;
        hCost   = 0.0f;
        mParent = null;
    }
Exemple #3
0
        public void LimitDepthFirstPlanSearch()
        {
            var state = new State();
            state.AddItem("Cash", 0);
            var action = new PlanningAction("Get Salary").Produces("Cash",100);
            state.PlanningActions.Add(action);

            var g0 = new Goal("Accumulate Cash").Target("Cash", 1000);

            IPlan p = new DFSPlan().SetMaxSearchDepth(3);
            p.Search(state, g0);

            Assert.That(p.GetPath().Count, Is.EqualTo(3));
        }
Exemple #4
0
        public void DontPerformAnyActionWhenNoActionIsAvailable()
        {
            var state = new State();
            state.AddItem("Cash", 99);
            var action = new PlanningAction("Not affordable").Consumes("Cash", 100).Produces("Harvester");
            state.PlanningActions.Add(action);

            var g0 = new Goal("Build Harvester").Target("Harvester", 1);

            IPlan p = new DFSPlan();
            p.Search(state, g0);

            Assert.That(p.GetPath().ToList().Count, Is.EqualTo(0));
        }
Exemple #5
0
        public void LimitDepthFirstPlanSearch()
        {
            var state = new State();

            state.AddItem("Cash", 0);
            var action = new PlanningAction("Get Salary").Produces("Cash", 100);

            state.PlanningActions.Add(action);

            var g0 = new Goal("Accumulate Cash").Target("Cash", 1000);

            IPlan p = new DFSPlan().SetMaxSearchDepth(3);

            p.Search(state, g0);

            Assert.That(p.GetPath().Count, Is.EqualTo(3));
        }
Exemple #6
0
        public void DontPerformAnyActionWhenNoActionIsAvailable()
        {
            var state = new State();

            state.AddItem("Cash", 99);
            var action = new PlanningAction("Not affordable").Consumes("Cash", 100).Produces("Harvester");

            state.PlanningActions.Add(action);

            var g0 = new Goal("Build Harvester").Target("Harvester", 1);

            IPlan p = new DFSPlan();

            p.Search(state, g0);

            Assert.That(p.GetPath().ToList().Count, Is.EqualTo(0));
        }
Exemple #7
0
    public void ApplyBackwardEffects(NodePlanning node, WorldState world, PlanningAction action)
    {
        switch (action.mActionType)
        {
        case PlanningAction.ActionType.AT_PICK_UP:
            world.ingredientsKept.Remove(action.mIngredient);

            break;

        case PlanningAction.ActionType.AT_GO_TO:
            Vector3 ingredientPos = FindIngredientOfType(action.mIngredient);
            node.mAction.mCost = (ingredientPos - mWorldState.cPos).magnitude;
            mWorldState.cPos   = ingredientPos;
            world.ingredientsVisited.Remove(action.mIngredient);
            break;
        }
    }
Exemple #8
0
    public bool MeetConditions(WorldState world, PlanningAction action)
    {
        bool    meets         = false;
        Vector3 ingredientPos = FindIngredientOfType(action.mIngredient);

        switch (action.mActionType)
        {
        case PlanningAction.ActionType.AT_GO_TO:
            meets = (!world.ingredientsKept.Contains(action.mIngredient) && world.finalRecipe[0].ingredients.Contains(action.mIngredient));
            break;

        case PlanningAction.ActionType.AT_PICK_UP:
            meets = (world.ingredientsKept.Contains(action.mIngredient) && (world.ingredientsVisited.Count) == world.ingredientsKept.Count);
            break;
        }

        return(meets);
    }
Exemple #9
0
 public RegressiveEdge(PlanningAction action, RegressiveNode sourceNode, RegressiveNode targetNode)
 {
     Action     = PreconditionUtils.EnsureNotNull(action, "action");
     SourceNode = sourceNode;
     TargetNode = targetNode;
 }
Exemple #10
0
 public ForwardEdge(PlanningAction action, ForwardNode sourceNode, ForwardNode targetNode)
 {
     this.Action     = PreconditionUtils.EnsureNotNull(action, "action");
     this.SourceNode = sourceNode;
     this.TargetNode = targetNode;
 }
Exemple #11
0
    public void ApplyAdditionalEffects(NodePlanning nodePlanning, WorldState mWorldState, PlanningAction action)
    {
        switch (action.mActionType)
        {
        case PlanningAction.ActionType.AT_GO_TO:
            Vector3 ingredientPos = FindIngredientOfType(action.mIngredient);
            nodePlanning.mAction.mCost = (ingredientPos - mWorldState.cPos).magnitude;
            mWorldState.cPos           = ingredientPos;
            break;

        case PlanningAction.ActionType.AT_PICK_UP:
            mWorldState.ingredientsKept.Add(action.mIngredient);
            break;

        case PlanningAction.ActionType.AT_GO_TO_KITCHEN:
            nodePlanning.mAction.mCost = (kitchen.transform.position - mWorldState.cPos).magnitude;
            mWorldState.cPos           = kitchen.transform.position;
            mWorldState.finalRecipe.Add(RecipeCompleted(mWorldState));
            break;

        default:
            break;
        }
    }