Exemplo n.º 1
0
 public void Recycle()
 {
     state.Recycle();
     state = null;
     goal.Recycle();
     goal = null;
     cachedNodes.Push(this);
 }
Exemplo n.º 2
0
 public void Recycle()
 {
     state.Recycle();
     state = null;
     Goal.Recycle();
     Goal = null;
     lock (cachedNodes)
     {
         cachedNodes.Push(this);
     }
 }
Exemplo n.º 3
0
 protected virtual void OnDestroy()
 {
     goal.Recycle();
 }
Exemplo n.º 4
0
    private void Init(IGoapPlanner <T, W> planner, ReGoapState <T, W> newGoal, ReGoapNode <T, W> parent, IReGoapAction <T, W> action)
    {
        expandList.Clear();

        this.planner = planner;
        this.parent  = parent;
        this.action  = action;
        if (action != null)
        {
            actionSettings = action.GetSettings(planner.GetCurrentAgent(), newGoal);
        }

        if (this.parent != null)
        {
            state = this.parent.GetState();
            // g(node)
            g = parent.GetPathCost();
        }
        else
        {
            state = (ReGoapState <T, W>)planner.GetCurrentAgent().GetMemory().GetWorldState().Clone();
        }

        var nextAction = parent == null ? null : parent.action;

        if (action != null)
        {
            // since in backward search we relax the problem all preconditions are valid but are added to the current goal
            var preconditions = action.GetPreconditions(newGoal, nextAction);
            goal = newGoal + preconditions;

            var effects = action.GetEffects(newGoal, nextAction);
            state += effects;
            g     += action.GetCost(newGoal, nextAction);

            // removing current action effects from goal, no need to do with to the whole state
            //  since the state is the sum of all the previous actions's effects.
            var missingState = ReGoapState <T, W> .Instantiate();

            goal.MissingDifference(effects, ref missingState);
            goal.Recycle();
            goal = missingState;

            // this is needed every step to make sure that any precondition is not already satisfied
            //  by the world state
            var worldMissingState = ReGoapState <T, W> .Instantiate();

            goal.MissingDifference(planner.GetCurrentAgent().GetMemory().GetWorldState(), ref worldMissingState);
            goal.Recycle();
            goal = worldMissingState;
        }
        else
        {
            var diff = ReGoapState <T, W> .Instantiate();

            newGoal.MissingDifference(state, ref diff);
            goal = diff;
        }
        h = goal.Count;
        // f(node) = g(node) + h(node)
        cost = g + h * heuristicMultiplier;
    }
Exemplo n.º 5
0
 void OnDestroy()
 {
     goal.Recycle();
 }
Exemplo n.º 6
0
 void OnDestroy()
 {
     state.Recycle();
 }
Exemplo n.º 7
0
 protected virtual void OnDestroy()
 {
     state.Recycle();
 }