Пример #1
0
        private void BuildOutPlan(Action action)
        {
            AddAction(action);

            if (action.IsPreconditionsMet())
            {
                m_valid = true;
            }
            else
            {
                Action[] preconditionActions = Array.FindAll <Action>(m_actions, a => a.Effect == action.PreCondition);

                int        minTotalCost   = int.MaxValue;
                ActionPlan bestActionPlan = null;

                foreach (Action preconditionAction in preconditionActions)
                {
                    ActionPlan proposedActionPlan = new ActionPlan(preconditionAction, m_actions);
                    if (proposedActionPlan.Valid && (proposedActionPlan.TotalCost <= minTotalCost))
                    {
                        bestActionPlan = proposedActionPlan;
                        minTotalCost   = bestActionPlan.TotalCost;
                    }
                }

                if (bestActionPlan != null)
                {
                    AddActionPlan(bestActionPlan);
                    m_valid = true;
                }
            }
        }
Пример #2
0
        public ActionPlan(string desiredEffect, Action[] actions)
        {
            m_actions = actions;
            m_plan    = new List <Action>();

            Action[] goalActions = Array.FindAll(actions, a => a.Effect == desiredEffect);

            int        minTotalCost       = int.MaxValue;
            ActionPlan bestGoalActionPlan = null;

            foreach (Action goalAction in goalActions)
            {
                ActionPlan goalActionPlan = new ActionPlan(goalAction, actions);

                if (goalActionPlan.Valid && goalActionPlan.TotalCost < minTotalCost)
                {
                    bestGoalActionPlan = goalActionPlan;
                    minTotalCost       = goalActionPlan.TotalCost;
                }
            }

            if (bestGoalActionPlan != null)
            {
                AddActionPlan(bestGoalActionPlan);
                m_valid = true;
            }
        }
Пример #3
0
        public ActionPlan Plan(Goal goal, Action[] actions)
        {
            // Iterate through passed in Actions to determine which path will lead to the passed in Goal.
            ActionPlan blah = new ActionPlan(goal.DesiredEffect, actions);

            return(blah);
        }
Пример #4
0
    void Think()
    {
        if (m_currentActionSet == null || m_currentActionSet.Count == 0)
        {
            GOAP.ActionPlan actionPlan = m_actionPlanner.Plan(m_insectGoals[1], m_insectActions.ToArray());

            if (actionPlan != null && actionPlan.Valid)
            {
                m_currentActionSet = new Stack(actionPlan.Plan);
            }
        }



        if (m_memory.TargetInsect != null)
        {
            Move(m_memory.TargetInsect.transform.position);

            if ((m_memory.TargetInsect.transform.position - this.transform.position).magnitude > attackRadius)
            {
                Attack(m_memory.TargetInsect);
            }
        }
        else if (m_memory.ReachedDestination != true)
        {
            Move(m_memory.TargetPosition);
        }
        else
        {
            //FindNewTargetSpot();
        }
    }
Пример #5
0
 private void AddActionPlan(ActionPlan plan)
 {
     m_plan.InsertRange(0, plan.m_plan);
     m_totalCost += plan.TotalCost;
 }