Пример #1
0
    // Called when the player requests a move.
    public bool PlayerUpdate(string playerAction)
    {
        //Debug.Log (playerAction);

        // A record for whether this is a valid action.
        bool validAction = false;

        stateManager.PlayerTurn = false;

        foreach (StateSpaceEdge edge in root.outgoing)
        {
            // If we find the edge, record it and log it.
            if (edge.Action.ToString().Equals(playerAction))
            {
                playerActionEdge = edge;
                playerLog.Enqueue(edge.Action);
                validAction = true;
                break;
            }
        }

        // If we have detected a valid action, process it through the mediation engine.
        if (validAction)
        {
            Thread updatePlayerPlan = new Thread(UpdatePlayerPlan);
            updatePlayerPlan.Start();
        }
        else
        {
            stateManager.PlayerTurn = true;
        }

        return(validAction);
    }
Пример #2
0
    // Called when the player requests a move.
    public bool PlayerUpdate(string playerAction)
    {
        //Debug.Log (playerAction);

        // A record for whether this is a valid action.
        bool validAction = false;

        stateManager.PlayerTurn = false;
        StateSpaceEdge matchingEdge = null;

        foreach (StateSpaceEdge edge in root.outgoing)
        {
            if (edge.Action.ToString().Equals(playerAction))
            {
                matchingEdge = edge;
            }
        }

        if (matchingEdge != null)
        {
            validAction = true;

            currentEdge = matchingEdge;
            Thread updatePlan = new Thread(UpdatePlan);
            updatePlan.Start();
        }
        else
        {
            stateManager.PlayerTurn = true;
        }

        return(validAction);
    }
Пример #3
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'.");
            }
        }
Пример #4
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'.");
            }
        }