Exemple #1
0
        public List <INode <ReGoapState <T, W> > > Expand()
        {
            expandList.Clear();

            var agent   = planner.GetCurrentAgent();
            var actions = agent.GetActionsSet();

            for (var index = actions.Count - 1; index >= 0; index--)
            {
                var possibleAction = actions[index];
                possibleAction.Precalculations(agent, goal);
                var precond = possibleAction.GetPreconditions(goal, action);
                var effects = possibleAction.GetEffects(goal, action);
                if (possibleAction == action)
                {
                    continue;
                }
                if (effects.HasAny(goal) &&          // any effect is the current goal
                    !goal.HasAnyConflict(effects) && // no effect is conflicting with the goal
                    !goal.HasAnyConflict(precond) && // no precondition is conflicting with the goal
                    possibleAction.CheckProceduralCondition(agent, goal, parent != null ? parent.action : null))
                {
                    var newGoal = goal;
                    expandList.Add(Instantiate(planner, newGoal, this, possibleAction));
                }
            }
            return(expandList);
        }
Exemple #2
0
        public List <INode <ReGoapState <T, W> > > Expand()
        {
            expandList.Clear();

            var agent   = planner.GetCurrentAgent();
            var actions = agent.GetActionsSet();

            GoapActionStackData <T, W> stackData;

            stackData.currentState = state;
            stackData.goalState    = goal;
            stackData.next         = action;
            stackData.agent        = agent;
            stackData.settings     = null;
            for (var index = actions.Count - 1; index >= 0; index--)
            {
                var possibleAction = actions[index];

                possibleAction.Precalculations(stackData);
                var settingsList = possibleAction.GetSettings(stackData);
                foreach (var settings in settingsList)
                {
                    stackData.settings = settings;
                    var precond = possibleAction.GetPreconditions(stackData);
                    var effects = possibleAction.GetEffects(stackData);

                    if (effects.HasAny(goal) &&                   // any effect is the current goal
                        !goal.HasAnyConflict(effects, precond) && // no precondition is conflicting with the goal or has conflict but the effects fulfils the goal
                        !goal.HasAnyConflict(effects) &&          // no effect is conflicting with the goal
                        possibleAction.CheckProceduralCondition(stackData))
                    {
                        var newGoal = goal;
                        expandList.Add(Instantiate(planner, newGoal, this, possibleAction, settings));
                    }
                }
            }
            return(expandList);
        }
Exemple #3
0
    public IEnumerator <IReGoapAction <T, W> > GetPossibleActionsEnumerator()
    {
        var agent   = planner.GetCurrentAgent();
        var actions = agent.GetActionsSet();

        for (var index = actions.Count - 1; index >= 0; index--)
        {
            var possibleAction = actions[index];
            possibleAction.Precalculations(agent, goal);
            var precond = possibleAction.GetPreconditions(goal, action);
            var effects = possibleAction.GetEffects(goal, action);
            if (possibleAction == action)
            {
                continue;
            }
            if (effects.HasAny(goal) &&          // any effect is the current goal
                !goal.HasAnyConflict(effects) && // no effect is conflicting with the goal
                !goal.HasAnyConflict(precond) && // no precondition is conflicting with the goal
                possibleAction.CheckProceduralCondition(agent, goal, parent != null ? parent.action : null))
            {
                yield return(possibleAction);
            }
        }
    }
Exemple #4
0
        private void Init(ReGoapAgent agent, ReGoapState newGoalState, ReGoapNode parent, ReGoapAction action)
        {
            expandList.Clear();

            ReGoapState goal = null;

            this.reGoapAgent = agent;
            this.parentNode  = parent;
            this.action      = action;
            if (action != null)
            {
                actionSettings = action.GetSettings(newGoalState);
            }

            if (parentNode != null)
            {
                agentReGoapState = parentNode.GetState().Clone();
                g = parentNode.GetPathCost();
            }
            else
            {
                ReGoapState reGoapState = agent.GetWorldState();
                agentReGoapState = reGoapState.Clone();
            }

            if (action != null)
            {
                // create a new instance of the goal based on the paren't goal
                goal = ReGoapState.Instantiate(newGoalState);

                var preconditions = action.GetPreconditions(goal);
                var effects       = action.GetEffects(goal);
                // adding the action's effects to the current node's state
                agentReGoapState.AddFromState(effects);
                // addding the action's cost to the node's total cost
                g += action.GetCost();
                // add all preconditions of the current action to the goal
                goal.AddFromState(preconditions);
                // removes from goal all the conditions that are now fullfiled in the node's state
                goal.ReplaceWithMissingDifference(agentReGoapState);
            }
            else
            {
                goal = newGoalState.MissingDifference(agentReGoapState);
            }
            h    = goal.Count;
            cost = g + h;

            //Expand(goal);

            expandList.Clear();

            List <ReGoapAction> actionsList = reGoapAgent.GetActionsSet();

            for (var index = actionsList.Count - 1; index >= 0; index--)
            {
                ReGoapAction possibleAction = actionsList[index];

                if (!possibleAction.CheckProceduralCondition())  // 执行条件不满足排除掉
                {
                    continue;
                }

                ReGoapState precond = possibleAction.GetPreconditions(goal);
                ReGoapState effects = possibleAction.GetEffects(goal);

                if (!ReGoapState.HasAny(effects, goal)) // any effect is the current goal
                {
                    continue;
                }

                if (!ReGoapState.HasAnyConflict(precond, goal))
                {
                    ReGoapNode reGoapNode = new ReGoapNode(reGoapAgent, goal, this, possibleAction);
                    expandList.Add(reGoapNode);
                }
            }
        }