/// <summary> /// Given a character, node, and tree, returns the character's knowledge of the world history. /// </summary> /// <param name="character">The character.</param> /// <param name="node">The node that corresponds to the current state.</param> /// <param name="tree">The mediation tree.</param> /// <returns>A list of action-state pairs that represent what the character knows.</returns> public static List <Tuple <Operator, State> > GetWorldKnowledge(string character, MediationTreeNode node, MediationTree tree) { // An object to hold the character's knowledge of the world history. List <Tuple <Operator, State> > knowledge = new List <Tuple <Operator, State> >(); // Get the objective world history. List <MediationTreeNode> history = GetWorldHistory(node, tree); // Loop through the nodes in the world history branch... foreach (MediationTreeNode current in history) { // Create a new action. Operator action = null; // Make sure the current node is not the root. if (current.Incoming != null) { // Check if the character observes the incoming action. if (RobertsonMicrotheory.Observes(character, current.Incoming.Action, current.State.Predicates)) { // If so, remember that the character observed the action. action = current.Incoming.Action.Clone() as Operator; } } // Create a new state consisting only of terms the character observed. State state = new State(RobertsonMicrotheory.FullKnowledgeState(tree.Root.Domain.Predicates, tree.Root.Problem.ObjectsByType, current.State.Predicates, character)); // Store the observed action-state pair as a tuple. knowledge.Add(new Tuple <Operator, State>(action, state)); } // Return the sequence of observed action-state pairs. return(knowledge); }
// Creates and returns a new node. public static StateSpaceNode CreateNode(Planner planner, Domain domain, Problem problem, Plan plan, State state) { // Create a node for the current state. StateSpaceNode root = new StateSpaceNode(); // Record that a node was created. StateSpaceMediator.NodeCount++; // Check if the node is a leaf. if (StateSpaceSearchTools.CheckLeaf(plan, state, root)) { return(root); } // Set the node's domain. root.domain = domain; // Set the node's problem. root.problem = problem; // Set the node's plan. root.plan = plan; // Set the node's state. root.state = state; // Find out what the player knows. root.problem.Initial = RobertsonMicrotheory.Annotate(problem.Initial, problem.Player); // Find all outgoing user actions from this state. root.outgoing = StateSpaceTools.GetAllPossibleActions(domain, problem, plan, state); // Record the number of outgoing edges. StateSpaceMediator.OutgoingEdgesCount = StateSpaceMediator.OutgoingEdgesCount + root.outgoing.Count; // Return the current node. return(root); }
// Build the mediation tree using a depth-first strategy. public static StateSpaceNode BuildTree(Planner planner, Domain domain, Problem problem, Plan plan, State state, int depth) { // Create a node for the current state. StateSpaceNode root = new StateSpaceNode(); // Record that a node was created. NodeCount++; // Return any empty plans. if (plan.Steps.Count == 0) { // If the goal is satisfied... if (state.Satisfies(plan.GoalStep.Preconditions)) { // Differentiate a satisfied goal. root.satisfiesGoal = true; // Record that a goal state was reached. GoalStateCount++; } else { // Record that a dead end state was reached. DeadEndCount++; } // Return the leaf node. return(root); } // Set the node's domain. root.domain = domain; // Set the node's problem. root.problem = problem; // Set the node's plan. root.plan = plan; // Set the node's state. root.state = state; // Find out what the player knows. root.problem.Initial = RobertsonMicrotheory.Annotate(problem.Initial, problem.Player); // Find all outgoing user actions from this state. root.outgoing = StateSpaceTools.GetAllPossibleActions(domain, problem, plan, state); // Return the node if the depth limit has been reached. if (depth <= 0) { return(root); } // Loop through the possible actions. foreach (StateSpaceEdge edge in root.outgoing) { StateSpaceNode child = ExpandTree(planner, domain, problem, plan.Clone() as Plan, state.Clone() as State, edge, depth); // Set the child's parent to this node. child.parent = root; // Add the child to the parent's collection of children, by way of the current action. root.children[edge] = child; } // Return the current node. return(root); }