public STRIPSNode(STRIPSNode previousAction, float actionCost, List <KeyValuePair <string, bool> > state, STRIPSAction action) { PreviousAction = previousAction; ActionCost = actionCost; State = state; Action = action; }
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); }
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); }
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); }
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); } } }
private void GenerateActionsToPerformQueue(Queue <STRIPSAction> actionsToPerformQueue, STRIPSNode node) { if (node.PreviousAction != null) { GenerateActionsToPerformQueue(actionsToPerformQueue, node.PreviousAction); } if (node.Action != null) { actionsToPerformQueue.Enqueue(node.Action); } }