コード例 #1
0
 public void RemoveState(GOAP_StatesList statesToRemove)
 {
     for (int i = 0; i < statesToRemove.states.Count; i++)
     {
         if (states.Contains(statesToRemove.states[i]))
         {
             states.Remove(statesToRemove.states[i]);
         }
     }
 }
コード例 #2
0
 public void AddStates(GOAP_StatesList statesToAdd)
 {
     for (int i = 0; i < statesToAdd.states.Count; i++)
     {
         if (!states.Contains(statesToAdd.states[i]))
         {
             states.Add(statesToAdd.states[i]);
         }
     }
 }
コード例 #3
0
    public int CompareState(GOAP_StatesList subSet)
    {
        int differance = 0;

        for (int i = 0; i < subSet.states.Count; i++)
        {
            if (!states.Contains(subSet.states[i]))
            {
                differance++;
            }
        }

        return(differance);
    }
コード例 #4
0
 public GOAP_StatesList(GOAP_StatesList copy)
 {
     states = new List <GOAP_States>(copy.states);
 }
コード例 #5
0
 public SimulationStep(GOAP_StatesList worldState, GOAP_Action action, int depth)
 {
     this.worldState = worldState;
     this.action     = action;
     this.depth      = depth;
 }
コード例 #6
0
    private void Plan()
    {
        for (int i = 0; i < goals.Count; i++)
        {
            if (goals[i].isValid(this))
            {
                goal = goals[i];
                break;
            }
        }

        if (worldState.CompareState(goal.goalStates) == 0)
        {
            return;
        }

        currentPlan.Clear();
        Stack <SimulationStep> sim = new Stack <SimulationStep>();

        GOAP_Action[] simPlan = new GOAP_Action[maxPlanDepth];

        int minDepth = int.MaxValue;

        sim.Push(new SimulationStep(new GOAP_StatesList(worldState), null, 0));

        List <GOAP_States> targetStates = new List <GOAP_States>(goal.goalStates.states);

        while (sim.Count != 0)
        {
            currentSimData = sim.Pop();
            simPlan[currentSimData.depth] = currentSimData.action;

            if (currentSimData.depth > minDepth)
            {
                continue;
            }

            if (currentSimData.worldState.CompareState(goal.goalStates) == 0 || currentSimData.depth >= maxPlanDepth)
            {
                if (currentSimData.depth < minDepth)
                {
                    currentPlan.Clear();
                    for (int i = 0; i <= currentSimData.depth; i++)
                    {
                        if (simPlan[i] != null)
                        {
                            if (!currentPlan.Contains(simPlan[i]))
                            {
                                currentPlan.Enqueue(simPlan[i]);
                            }
                        }
                    }
                    minDepth = currentSimData.depth;
                }
            }
            else
            {
                for (int i = 0; i < actions.Count; i++)
                {
                    if (actions[i].isValid(this))
                    {
                        GOAP_StatesList newSimState = new GOAP_StatesList(currentSimData.worldState);
                        newSimState.AddStates(actions[i].resultStates);
                        sim.Push(new SimulationStep(newSimState, actions[i], (currentSimData.depth + 1)));
                    }
                }
            }
        }
    }