示例#1
0
 public STRIPSNode(STRIPSNode previousAction, float actionCost, List <KeyValuePair <string, bool> > state, STRIPSAction action)
 {
     PreviousAction = previousAction;
     ActionCost     = actionCost;
     State          = state;
     Action         = action;
 }
示例#2
0
        private void HandleSubplanning(List <STRIPSNode> plans, List <STRIPSAction> usableActions, List <KeyValuePair <string, bool> > goal, int level, Vector3 currentPosition, Spy spy,
                                       STRIPSAction action, STRIPSNode planNode)
        {
            var actionsForSubplanning = usableActions.Except(new List <STRIPSAction>()
            {
                action
            }).ToList();

            GenerateAllPossiblePlans(planNode, plans, actionsForSubplanning, goal, level + 1, currentPosition, spy);
        }
示例#3
0
        private static float CalculateActionCost(STRIPSNode parent, Vector3 currentPosition, STRIPSAction action)
        {
            var actionStartPosition = currentPosition;

            if (parent != null && parent.Action != null && parent.Action.ActionTarget != null)
            {
                actionStartPosition = parent.Action.ActionTarget.transform.position;
            }

            float cost = action.CalculateCost(actionStartPosition);

            return(cost);
        }
示例#4
0
        private bool FindTheBestPlan(Spy spy, List <KeyValuePair <string, bool> > currentState, List <KeyValuePair <string, bool> > objectives,
                                     List <STRIPSAction> usableActions, out STRIPSNode theBestPlan)
        {
            var plans    = new List <STRIPSNode>();
            var rootNode = new STRIPSNode(null, 0, currentState, null);

            GenerateAllPossiblePlans(rootNode, plans, usableActions, objectives, 0, spy.transform.position, spy);

            if (!plans.Any())
            {
                theBestPlan = null;
                return(false);
            }

            theBestPlan = plans.OrderBy(p => p.ActionCost).First();
            return(true);
        }
示例#5
0
        private void GenerateAllPossiblePlans(STRIPSNode parent, List <STRIPSNode> plans, List <STRIPSAction> usableActions, List <KeyValuePair <string, bool> > goal, int level, Vector3 currentPosition, Spy spy)
        {
            var actionWithPreconditionsFulfilled =
                usableActions.Where(a => ArePreconditionsFulfilled(a.Preconditions, parent.State));

            foreach (var action in actionWithPreconditionsFulfilled)
            {
                HandleHideInBushAction(spy, action);

                var simulatedCurrentState = SimulateCurrentStateAfterActionExecution(parent.State, action.Postconditions);

                var cost     = CalculateActionCost(parent, currentPosition, action);
                var planNode = new STRIPSNode(parent, parent.ActionCost + cost, simulatedCurrentState, action);

                if (ArePreconditionsFulfilled(goal, simulatedCurrentState))
                {
                    plans.Add(planNode);
                }
                else
                {
                    HandleSubplanning(plans, usableActions, goal, level, currentPosition, spy, action, planNode);
                }
            }
        }
示例#6
0
        private void GenerateActionsToPerformQueue(Queue <STRIPSAction> actionsToPerformQueue, STRIPSNode node)
        {
            if (node.PreviousAction != null)
            {
                GenerateActionsToPerformQueue(actionsToPerformQueue, node.PreviousAction);
            }

            if (node.Action != null)
            {
                actionsToPerformQueue.Enqueue(node.Action);
            }
        }