Beispiel #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 (effects.HasAnyGoodForGoal(state, goal) &&           // any effect is the current goal
                    !goal.HasAnyConflictPrecond(effects, precond) &&    // no precondition is conflicting with the goal (non-arithmetic)
                    !goal.HasAnyConflictEffect(effects) &&              //no effect is conflicting with goal (non-arithmetic)
                    !goal.IsNotHelpfulAtAll(effects, precond, state) && //(arithmetic)
                    possibleAction.CheckProceduralCondition(agent, goal, parent != null ? parent.action : null))
                {
                    var newGoal = goal;
                    var newNode = Instantiate(planner, newGoal, this, possibleAction);
                    expandList.Add(newNode);
                    Utilities.ReGoapLogger.Log(string.Format("   oooo Expanded node: action: {0}\n\t effect {1}\n\t precond {2}\n\t goal {3}", possibleAction.GetName(), effects, precond, newNode.GoalString));
                }
                else
                {
                    Utilities.ReGoapLogger.Log(string.Format("   xxxx Expanded node: action: {0}\n\t effect {1}\n\t precond {2}", possibleAction.GetName(), effects, precond));
                }
            }
            return(expandList);
        }