// Create the applicable constituent action for a state. public static StateSpaceEdge GetConstituentAction(Domain domain, Problem problem, Plan plan, State state) { // Iterate through the plan to find the next player step. for (int i = 0; i < plan.Steps.Count; i++) { if (plan.Steps[i].Arity > 0) { // Check to see if the next step in the plan is performed by the player. if (plan.Steps[i].TermAt(0).Equals(problem.Player)) { // Create a new plan. Plan newPlan = plan.Clone() as Plan; // Remove the current step from the new plan. newPlan.Steps.RemoveAt(i); // Add the current step to the start of the steps. newPlan.Steps.Insert(0, plan.Steps[i].Clone() as Operator); // Check to see if the new plan is valid. if (PlanSimulator.VerifyPlan(newPlan, state, problem.Objects)) { // The current step is constituent. return(new StateSpaceEdge(plan.Steps[i].Clone() as Operator, ActionType.Constituent)); } // Exit the loop. i = plan.Steps.Count; } } } // Otherwise, return a blank step as the user's constituent action. return(new StateSpaceEdge(new Operator("do nothing"), ActionType.Constituent)); }
// Create the applicable constituent action for a state. public static MediationTreeEdge GetConstituentAction(string actor, MediationTreeNode node) { // Iterate through the plan to find the next player step. for (int i = 0; i < node.Plan.Steps.Count; i++) { if (node.Plan.Steps[i].Arity > 0) { // Check to see if the next step in the plan is performed by the player. if (node.Plan.Steps[i].TermAt(0).Equals(actor)) { // Create a new plan. Plan newPlan = node.Plan.Clone() as Plan; // Remove the current step from the new plan. newPlan.Steps.RemoveAt(i); // Add the current step to the start of the steps. newPlan.Steps.Insert(0, node.Plan.Steps[i].Clone() as Operator); // Check to see if the new plan is valid. if (PlanSimulator.VerifyPlan(newPlan, node.State, node.Problem.Objects)) { // The current step is constituent. return(new MediationTreeEdge(node.Plan.Steps[i].Clone() as Operator, ActionType.Constituent, node.ID)); } // Exit the loop. i = node.Plan.Steps.Count; } } } // Otherwise, return a blank step as the user's constituent action. return(new MediationTreeEdge(new Operator("do nothing"), ActionType.Constituent, node.ID)); }
// Creates a list of actions for computer controlled characters to perform. public static List <IOperator> GetSystemActions(Plan plan, List <string> moved, List <IOperator> actions) { // Iterate through the plan to find the next player step. for (int i = 0; i < plan.Steps.Count; i++) { // Make sure the step has arity. if (plan.Steps[i].Arity > 0) { // A placeholder to check if the character has already moved. bool hasMoved = false; // Loop through the characters that have moved. foreach (string character in moved) { // If it matches the actor... if (plan.Steps[i].TermAt(0).Equals(character)) { // ...mark as already moved. hasMoved = true; } } // If the character has not moved yet. if (!hasMoved) { // Create a new plan. Plan newPlan = plan.Clone() as Plan; // Remove the current step from the new plan. newPlan.Steps.RemoveAt(i); // Add the current step to the start of the steps. newPlan.Steps.Insert(0, plan.Steps[i].Clone() as Operator); // Check to see if the new plan is valid. if (PlanSimulator.VerifyPlan(newPlan, plan.Initial as State, plan.Problem.Objects)) { // Add the step to the list of actions. actions.Add(newPlan.Steps[0]); // Remove the first step from the plan. newPlan.Steps.RemoveAt(0); // Add the character to the list of moved characters. moved.Add(plan.Steps[i].TermAt(0)); // Recursively call the function. return(GetSystemActions(newPlan, moved, actions)); } } } } // Return the list of actions to take. return(actions); }