Esempio n. 1
0
        // Creates a single tree of specified depth.
        private static List <Tuple <String, String> > SingleTree(string domainName, string timeStamp, int depth)
        {
            // Read in the domain file.
            Domain domain = Parser.GetDomain(Parser.GetTopDirectory() + @"Benchmarks\" + domainName + @"\domain.pddl", PlanType.StateSpace);

            // Read in the problem file.
            Problem problem = Parser.GetProblem(Parser.GetTopDirectory() + @"Benchmarks\" + domainName + @"\prob01.pddl");

            // Find an initial plan.
            Plan plan = FastDownward.Plan(domain, problem);

            // Create a stopwatch object.
            Stopwatch watch = new Stopwatch();

            // Start the stopwatch.
            watch.Start();

            // Use the state space mediator to build the tree.
            StateSpaceNode root = StateSpaceMediator.BuildTree(Planner.FastDownward, domain, problem, plan, plan.Initial as State, depth);

            // Stop the stopwatch.
            watch.Stop();

            // Write the tree to disk using HTML files and return the summary object.
            return(WriteTree(domainName, timeStamp, depth, watch, root));
        }
Esempio n. 2
0
        public void StateSpaceMediatorZombieConstituentUpdateTest()
        {
            StateSpaceNode root  = StateSpaceMediator.BuildTree(Planner.FastDownward, testDomain, testProblem, testPlan, testPlan.Initial as State, 1);
            StateSpaceNode child = root.children[root.outgoing[0]] as StateSpaceNode;

            Assert.AreNotEqual(root.problem.Initial, child.problem.Initial);
        }
Esempio n. 3
0
        public void StateSpaceMediatorExceptionalActionTest()
        {
            StateSpaceNode root = StateSpaceMediator.BuildTree(Planner.Glaive, testDomain, testProblem, testPlan, testPlan.Initial as State, 3);

            Assert.AreEqual(root.outgoing[1].ActionType, ActionType.Exceptional);
            Assert.AreEqual(root.outgoing[1].Action.Name, "move-location");
        }
Esempio n. 4
0
        public void StateSpaceMediatorExceptionalUpdateIntentionTest()
        {
            StateSpaceNode root  = StateSpaceMediator.BuildTree(Planner.Glaive, testDomain, testProblem, testPlan, testPlan.Initial as State, 1);
            StateSpaceNode child = root.children[root.outgoing[1]] as StateSpaceNode;

            Assert.AreEqual(child.problem.Intentions.Count, 2);
            Assert.AreNotEqual(child.plan.Steps.Count, 4);
        }
Esempio n. 5
0
        public void StateSpaceMediatorExampleStateUpdateTest()
        {
            StateSpaceMediator.CEDeletion = true;
            StateSpaceNode root  = StateSpaceMediator.BuildTree(Planner.FastDownward, testDomain, testProblem, testPlan, testPlan.Initial as State, 3);
            StateSpaceNode child = root.children[root.outgoing[2]] as StateSpaceNode;

            Assert.IsTrue(child.Goal);
        }
Esempio n. 6
0
        public void StateSpaceMediatorExampleCEDeleteTest()
        {
            StateSpaceMediator.CEDeletion = true;
            StateSpaceNode root  = StateSpaceMediator.BuildTree(Planner.FastDownward, testDomain, testProblem, testPlan, testPlan.Initial as State, 3);
            StateSpaceNode child = root.children[root.outgoing[2]] as StateSpaceNode;

            Assert.IsTrue(child.incoming.Action.Conditionals.Count == 0);
        }
Esempio n. 7
0
        public void StateSpaceMediatorExampleCEParseTest()
        {
            StateSpaceNode root  = StateSpaceMediator.BuildTree(Planner.FastDownward, testDomain, testProblem, testPlan, testPlan.Initial as State, 3);
            StateSpaceNode child = root.children[root.outgoing[1]] as StateSpaceNode;

            Assert.IsFalse(child.incoming.Action.Effects.Contains(new Predicate("when", new List <ITerm> {
            }, true)));
        }
Esempio n. 8
0
    public void JumpToState(List <Predicate> newPredicates)
    {
        // Create and store the new state object.
        state = new State(newPredicates, null, null);

        // Create the initial node of mediation.
        root = StateSpaceMediator.BuildTree(domain, problem, plan, state, 0);

        // Set the state manager's predicates.
        stateManager.Predicates = state.Predicates;

        // Ask the state manager to refresh the world.
        stateManager.Refresh();
    }
Esempio n. 9
0
    // Use this for initialization
    void Start( )
    {
        // Set the path to the top directory.
        Parser.path = Directory.GetParent(Application.dataPath).FullName + "/";

        // Parse the domain and problem files, and get the initial plan.
        domain  = Parser.GetDomain(Parser.GetTopDirectory() + @"Benchmarks/" + domainName + @"/domain.pddl", PlanType.StateSpace);
        problem = Parser.GetProblem(Parser.GetTopDirectory() + @"Benchmarks/" + domainName + "/" + problemName + ".pddl");
        plan    = PlannerInterface.Plan(planner, domain, problem);

        // A test for the planner.
        if (plan.Steps.Count > 0)
        {
            Debug.Log("System loaded.");
        }
        else
        {
            Debug.Log("System not working or no plan exists.");
        }

        state      = plan.GetFirstState();                             // Find the first state.
        validState = true;                                             // Initialize the valid state.

        GameObject level = GameObject.Find("Level");                   // Find the level game object.

        stateManager            = level.GetComponent <StateManager>(); // Set the state manager.
        stateManager.Problem    = problem;
        stateManager.Predicates = state.Predicates;                    // Set the state manager's predicates.

        generator = level.GetComponent <MapManager>();                 // Set the level generator.
        generator.CreateLevel();                                       // Generate the level.

        // Create the initial node of mediation.
        root           = StateSpaceMediator.BuildTree(planner, domain, problem, plan, state, 0);
        frontier       = new Hashtable();            // Initialize the frontier.
        frontierThread = new Thread(ExpandFrontier); // Expand the frontier in a new thread.
        frontierThread.Start();                      // Start the thread.

        // Initialize the player's environment model and action log.
        playerEnvironmentModel = new EnvironmentModel(stateManager.PlayerName, domain, problem);
        actionLog = new List <Tuple <string, string> >();

        // Initialize the player log with a decent size.
        playerLog = new Queue <IOperator>(3 * plan.Steps.Count);

        #region Initialize the Experiment

        // Generate the participant's ID
        participantIDGenerator = new RNGCryptoServiceProvider();

        byte[] idBytes = new byte[4];
        participantIDGenerator.GetBytes(idBytes);
        participantID = BitConverter.ToInt32(idBytes, 0);
        PlayerPrefs.SetInt("participantID", participantID);

        // Compute and create the participant's output folder.
        participantFolder = Parser.GetTopDirectory() + @"Benchmarks/" + domain.Name.ToLower() +
                            @"/output/" + participantID + @"/";

        Directory.CreateDirectory(participantFolder);

        playerTurnCounter = 0;

        #endregion

        // Start the wizard conversation.
        DialogueManager.StartConversation("Wizard");
    }
Esempio n. 10
0
        public void StateSpaceMediatorArthActionTest()
        {
            StateSpaceNode root = StateSpaceMediator.BuildTree(Planner.Glaive, testDomain, testProblem, testPlan, testPlan.Initial as State, 3);

            Assert.AreEqual(root.outgoing.Count, 3);
        }
Esempio n. 11
0
    // Use this for initialization
    void Start()
    {
        Debug.Log(Screen.width + " " + Screen.height);
        int num = UnityEngine.Random.Range(1, 4);

        domainName += num.ToString();

        Debug.Log(domainName + " " + num);

        // Set the path to the top directory.
        Parser.path = Path.GetFullPath(".") + "\\";

        Debug.Log(Parser.path);

        // Parse the domain file.
        domain = Parser.GetDomain(Parser.GetTopDirectory() + @"Benchmarks\" + domainName + @"\domain.pddl", PlanType.StateSpace);

        // Parse the problem file.
        problem = Parser.GetProblem(Parser.GetTopDirectory() + @"Benchmarks\" + domainName + @"\prob01.pddl");

        // Find the initial plan.
        plan = FastDownward.Plan(domain, problem);

        // A test for the planner.
        if (plan.Steps.Count > 0)
        {
            Debug.Log("Planner is working.");
        }
        else
        {
            Debug.Log("Planner is not working or no plan exists.");
            RestartGame();
        }

        // Find the first state.
        state = plan.GetFirstState();

        // Find the level game object.
        GameObject level = GameObject.Find("Level");

        // Set the state manager.
        stateManager = level.GetComponent <StateManager>();

        // Set the level generator.
        generator = level.GetComponent <LevelGenerator>();

        // Set the state manager's predicates.
        stateManager.Predicates = state.Predicates;

        // Find the UI game object.
        GameObject ui = GameObject.Find("UI");

        // Set the ui generator.
        uiGenerator = ui.GetComponent <UI>();

        // Setup the UI.
        uiGenerator.GenerateUI();

        // Generate the level.
        generator.CreateLevel();

        // Create the initial node of mediation.
        root = StateSpaceMediator.BuildTree(domain, problem, plan, state, 0);

        // Initialize the frontier.
        frontier = new Hashtable();

        // Expand the frontier in a new thread.
        frontierThread = new Thread(ExpandFrontier);

        // Start the thread.
        frontierThread.Start();

        // Initialize the camera fade.
        iTween.CameraFadeAdd();

        // Initialize the valid state.
        validState = true;

        goal = false;

        needUpdate = false;
    }
Esempio n. 12
0
        /// <summary>
        /// An online text-based command line game that is a traversal of mediation space.
        /// </summary>
        /// <param name="domainName">The game domain.</param>
        /// <param name="debug">Whether or not debug mode is enabled.</param>
        public static void Play()
        {
            Console.Clear();
            string domainName = "";

            // Make sure the file exists.
            while
            (!File.Exists(Parser.GetTopDirectory() + @"Benchmarks\" + domainName + @"\domain.pddl") ||
             !File.Exists(Parser.GetTopDirectory() + @"Benchmarks\" + domainName + @"\prob01.pddl"))
            {
                // Prompt the user for game name.
                Console.WriteLine("What would you like to play?");
                Console.WriteLine("     Type 'exit' to end program.");
                Console.WriteLine("     Type 'path' to modify the directory.");
                Console.WriteLine("     Type 'planner' to choose the planner.");
                Console.WriteLine("     Type 'help' to print game titles.");
                Console.Write("     Type 'debug' to turn debug mode ");
                if (debug)
                {
                    Console.WriteLine("off.");
                }
                else
                {
                    Console.WriteLine("on.");
                }
                Console.WriteLine();
                Console.Write(">");

                // Read in the game to load.
                domainName = Console.ReadLine().ToLower();

                // Print domains if prompted.
                if (domainName.Equals("help"))
                {
                    Console.WriteLine();
                    if (System.IO.Directory.Exists(Parser.GetTopDirectory() + @"Benchmarks\"))
                    {
                        foreach (string file in Directory.GetFileSystemEntries(Parser.GetTopDirectory() + @"Benchmarks\"))
                        {
                            Console.WriteLine(Path.GetFileName(file));
                        }

                        Console.WriteLine();
                        Console.Write(">");

                        // Read in the game to load.
                        domainName = Console.ReadLine().ToLower();
                    }
                    else
                    {
                        Console.WriteLine(Parser.GetTopDirectory() + @"Benchmarks\ does not exist!");
                        Console.ReadKey();
                        domainName = "482990adkdlllifkdlkfjlaoow";
                    }
                }

                // Rewrite directory if prompted.
                if (domainName.Equals("path"))
                {
                    Console.WriteLine();
                    Console.WriteLine("Your current game directory is: " + Parser.GetTopDirectory());
                    Console.WriteLine("Enter new path.");
                    Console.WriteLine();
                    Console.Write(">");
                    string newPath = Console.ReadLine();
                    Console.WriteLine();

                    if (Directory.Exists(newPath + @"Benchmarks\"))
                    {
                        Parser.path = newPath;
                    }
                    else
                    {
                        Console.WriteLine("Sorry, " + newPath + @"Benchmarks\" + " does not exist.");
                        Console.ReadKey();
                    }
                }

                // Change the planner if prompted.
                if (domainName.Equals("planner"))
                {
                    Console.WriteLine();
                    Console.WriteLine("Your current planner is: " + planner);
                    Console.WriteLine("Enter new planner.");
                    Console.WriteLine();
                    Console.Write(">");
                    string newPlanner = Console.ReadLine();
                    Console.WriteLine();

                    if (Enum.IsDefined(typeof(Planner), newPlanner))
                    {
                        planner = (Planner)Enum.Parse(typeof(Planner), newPlanner, true);
                        Console.WriteLine("Your planner is now " + planner);
                        Console.ReadKey();
                    }
                    else
                    {
                        Console.WriteLine("Sorry, " + newPlanner + " does not exist.");
                        Console.ReadKey();
                    }
                }

                // Exit if prompted.
                if (domainName.Equals("exit"))
                {
                    Environment.Exit(0);
                }

                // Toggle debug if prompted
                if (domainName.Equals("debug"))
                {
                    debug = !debug;
                }

                if
                ((!File.Exists(Parser.GetTopDirectory() + @"Benchmarks\" + domainName + @"\domain.pddl") ||
                  !File.Exists(Parser.GetTopDirectory() + @"Benchmarks\" + domainName + @"\prob01.pddl")) &&
                 !domainName.Equals("debug") && !domainName.Equals("path") && !domainName.Equals("planner") && !domainName.Equals("482990adkdlllifkdlkfjlaoow"))
                {
                    // Prompt that the game doesn't exist.
                    Console.WriteLine();
                    Console.WriteLine("I'm sorry, but I can't find " + domainName.ToUpper());
                    Console.WriteLine();
                    Console.ReadKey();
                }

                // Clear the console screen.
                Console.Clear();
            }

            // Parse the domain file.
            domain = Parser.GetDomain(Parser.GetTopDirectory() + @"Benchmarks\" + domainName + @"\domain.pddl", PlanType.StateSpace);

            // Parse the problem file.
            problem = Parser.GetProblemWithTypes(Parser.GetTopDirectory() + @"Benchmarks\" + domainName + @"\prob01.pddl", domain);

            // Find the initial plan.
            if (planner.Equals(Planner.FastDownward))
            {
                plan = FastDownward.Plan(domain, problem);
            }
            else if (planner.Equals(Planner.Glaive))
            {
                plan = Glaive.Plan(domain, problem);
            }

            // Welcome the player to the game.
            Console.WriteLine("Welcome to " + domain.Name);

            // Find the first state.
            state = plan.GetFirstState();

            // Create the initial node of mediation space.
            root = StateSpaceMediator.BuildTree(planner, domain, problem, plan, state, 0);

            // Initialize a stopwatch for debugging.
            Stopwatch watch = new Stopwatch();

            // Present information about the player.
            command   = "look";
            arguments = new List <string> {
                "me"
            };
            Look();
            Console.WriteLine();

            // Present the initial state.
            command = "";
            Look();

            // Loop while this is false.
            bool exit = false;

            while (!exit)
            {
                // Initialize the frontier.
                frontier = new Hashtable();

                // Expand the frontier in a new thread.
                frontierThread = new Thread(ExpandFrontier);

                // Start the thread.
                frontierThread.Start();

                // Ask for input.
                Console.WriteLine();
                Console.Write(">");
                input = Console.ReadLine();

                // If in debug mode, start the stop watch.
                if (debug)
                {
                    watch.Reset();
                    watch.Start();
                }

                // Parse the command and its arguments.
                command   = ParseCommand(input).ToLower();
                arguments = ParseArguments(input);

                // Interpret the command.
                switch (command)
                {
                case "exit":
                    exit = true;
                    break;

                case "clear":
                    Console.Clear();
                    break;

                case "cls":
                    Console.Clear();
                    break;

                case "look":
                    Look();
                    break;

                case "help":
                    Help();
                    break;

                case "wait":
                    Console.Clear();
                    Wait();
                    break;

                default:
                    OneArg();
                    break;
                }

                // If debugging, write the current plan and the elapsed time.
                if (debug && plan.Steps.Count > 0 && !command.Equals("clear") && !command.Equals("cls"))
                {
                    Console.Out.WriteLine();
                    Console.WriteLine("Narrative Trajectory:");
                    int longestName = 0;
                    foreach (Operator step in plan.Steps)
                    {
                        if (step.TermAt(0).Length > longestName)
                        {
                            longestName = step.TermAt(0).Length;
                        }
                    }
                    string lastName = "";
                    foreach (Operator step in plan.Steps)
                    {
                        if (!step.TermAt(0).Equals(lastName))
                        {
                            lastName = step.TermAt(0);
                            Console.Out.Write("".PadLeft(5) + UppercaseFirst(step.TermAt(0)) + "".PadLeft(longestName - step.TermAt(0).Length + 1));
                        }
                        else
                        {
                            Console.Out.Write("".PadLeft(5) + "".PadLeft(longestName + 1));
                        }

                        string[] splitName = step.Name.Split('-');
                        Console.Out.Write(splitName[0] + "s ");
                        for (int i = 1; i < step.Name.Count(x => x == '-') + 1; i++)
                        {
                            Console.Out.Write(UppercaseFirst(step.TermAt(i)) + " ");
                        }
                        Console.Out.WriteLine();
                    }
                    Console.Out.WriteLine();
                    Console.Write("Elapsed time: ");
                    Console.Out.Write(watch.ElapsedMilliseconds);
                    Console.WriteLine("ms");
                }

                // Check for goal state.
                if (root.Goal)
                {
                    Console.WriteLine("GOAL STATE");
                    Console.ReadKey();
                    exit = true;
                }
                // Check for incompatible state.
                else if (root.Incompatible)
                {
                    Console.WriteLine("UNWINNABLE STATE");
                    Console.ReadKey();
                    exit = true;
                }

                if (exit)
                {
                    Console.Clear();
                }

                // Kill the frontier thread (this should be okay).
                frontierThread.Abort();
            }

            Game.Play();
        }