Esempio n. 1
0
    // Updates the plan that solves the planning problem from the player's current state.
    private void UpdatePlayerPlan( )
    {
        // Cache the old root
        StateSpaceNode oldRoot = root;

        // Update the root: if we've already computed it, get it, otherwise, expand (i.e. compute it).
        if (frontier.ContainsKey(playerActionEdge) && !playerActionEdge.Action.Name.Equals("donothing"))
        {
            root = frontier[playerActionEdge] as StateSpaceNode;
        }
        else
        {
            frontierThread.Abort();
            root = StateSpaceMediator.ExpandTree(planner, domain, problem, plan, state, playerActionEdge, 0);
        }

        // Set the root's parent.
        root.parent = oldRoot;

        // Cache the new root's properties.
        problem = root.problem;
        plan    = root.plan;
        state   = root.state;

        // Update the player model with the player's action and the resulting state predicates.
        playerEnvironmentModel.UpdateModel(playerActionEdge.Action, state.Predicates);

        // Let the mediator take its turn.
        stateNeedsUpdate = true;
    }
Esempio n. 2
0
    private void UpdatePlan()
    {
        if (frontier.ContainsKey(currentEdge))
        {
            //Debug.Log ("Cached");
            StateSpaceNode oldRoot = root;
            root        = frontier[currentEdge] as StateSpaceNode;
            root.parent = oldRoot;
            problem     = root.problem;
            plan        = root.plan;
            state       = root.state;
        }
        else
        {
            //Debug.Log ("Not Cached");
            frontierThread.Abort();
            StateSpaceNode oldRoot = root;
            root        = StateSpaceMediator.ExpandTree(domain, problem, plan, state, currentEdge, 0);
            root.parent = oldRoot;
            problem     = root.problem;
            plan        = root.plan;
            state       = root.state;
        }

        needUpdate = true;
    }
Esempio n. 3
0
        /// <summary>
        /// Moves along the outgoing wait edge from the current node in mediation space.
        /// </summary>
        public static void Wait()
        {
            // Provide feedback to the player.
            Console.Out.WriteLine();
            Console.Out.WriteLine("Time passes...");

            // Loop through the outgoing edges...
            foreach (StateSpaceEdge edge in root.outgoing)
            {
                // Identify
                if (edge.Action.Name.Equals("do-nothing"))
                {
                    if (frontier.ContainsKey(edge))
                    {
                        root    = frontier[edge] as StateSpaceNode;
                        domain  = root.domain;
                        problem = root.problem;
                        plan    = root.plan;
                        state   = root.state;
                    }
                    else
                    {
                        root    = StateSpaceMediator.ExpandTree(planner, domain, problem, plan, state, edge, 0);
                        domain  = root.domain;
                        problem = root.problem;
                        plan    = root.plan;
                        state   = root.state;
                    }
                }
            }

            Look();
        }
Esempio n. 4
0
 // Expand the frontier.
 private void ExpandFrontier( )
 {
     foreach (StateSpaceEdge edge in root.outgoing)
     {
         StateSpaceNode newNode = StateSpaceMediator.ExpandTree(planner, domain, problem, plan, state, edge, 0);
         frontier.Add(edge, newNode);
     }
 }
Esempio n. 5
0
        public static void Unknown()
        {
            StateSpaceEdge matchingEdge = null;

            foreach (StateSpaceEdge edge in root.outgoing)
            {
                if (command.Equals(edge.Action.Name) && arguments.Count == edge.Action.Arity)
                {
                    bool match = true;
                    for (int i = 0; i < arguments.Count; i++)
                    {
                        if (!arguments[i].ToLower().Equals(edge.Action.Predicate.TermAt(i)))
                        {
                            if (!arguments[i].ToLower().Equals(edge.Action.TermAt(i)))
                            {
                                match = false;
                            }
                        }
                    }

                    if (match)
                    {
                        matchingEdge = edge;
                    }
                }
            }

            if (matchingEdge != null)
            {
                root    = StateSpaceMediator.ExpandTree(planner, domain, problem, plan, state, matchingEdge, 0);
                problem = root.problem;
                plan    = root.plan;
                state   = root.state;

                Console.Clear();
                Look();
            }
            else
            {
                frontierThread.Abort();
                Console.Out.WriteLine();
                Random r = new Random();
                Console.Out.WriteLine(responses[r.Next(0, responses.Length)]);
                Console.Out.WriteLine("Try typing 'help'.");
            }
        }
Esempio n. 6
0
        public static void TwoArgs()
        {
            if (arguments.Count != 2)
            {
                Unknown();
                return;
            }

            StateSpaceEdge matchingEdge = null;

            foreach (StateSpaceEdge edge in root.outgoing)
            {
                if (edge.Action.Name.Count(x => x == '-') == 2)
                {
                    if (edge.Action.Name.Contains('-'))
                    {
                        string[] split = edge.Action.Name.Split('-');
                        if (command.Equals(split[0]))
                        {
                            if (arguments[0].ToLower().Equals(edge.Action.TermAt(1)))
                            {
                                if (arguments[1].ToLower().Equals(edge.Action.TermAt(2)))
                                {
                                    matchingEdge = edge;
                                }
                            }
                        }
                    }
                    else if (command.Equals(edge.Action.Name))
                    {
                        if (arguments[0].ToLower().Equals(edge.Action.TermAt(1)))
                        {
                            if (arguments[1].ToLower().Equals(edge.Action.TermAt(2)))
                            {
                                matchingEdge = edge;
                            }
                        }
                    }
                }
            }

            if (matchingEdge != null)
            {
                if (frontier.ContainsKey(matchingEdge))
                {
                    root    = frontier[matchingEdge] as StateSpaceNode;
                    domain  = root.domain;
                    problem = root.problem;
                    plan    = root.plan;
                    state   = root.state;
                }
                else
                {
                    frontierThread.Abort();
                    root    = StateSpaceMediator.ExpandTree(planner, domain, problem, plan, state, matchingEdge, 0);
                    domain  = root.domain;
                    problem = root.problem;
                    plan    = root.plan;
                    state   = root.state;
                }

                Console.Clear();
                Look();
            }
            else
            {
                Console.Out.WriteLine();
                Random r = new Random();
                Console.Out.WriteLine(responses[r.Next(0, responses.Length)]);
                Console.Out.WriteLine("Try typing 'help'.");
            }
        }