コード例 #1
0
        public void PathfindToOtherRoom()
        {
            MimanPathfinder2.ClearRoomNetwork();

            //D.onDLog += Console.WriteLine; // take care of the D.Log message from invalid path
            _eva.logger.AddListener(Console.WriteLine);

            SimpleRoomBuilder srb = new SimpleRoomBuilder(_world.roomRunner);

            srb.CreateRoomWithSize("DistantRoom", 10, 10);

            var p1 = _world.tingRunner.CreateTing <Point>("p1", new WorldCoordinate("Eden", new IntPoint(2, 4)));
            var p2 = _world.tingRunner.CreateTing <Point>("p2", new WorldCoordinate("DistantRoom", new IntPoint(4, 4)));

            // Add doors
            var door1 = _world.tingRunner.CreateTing <Door>("Door1", new WorldCoordinate("Eden", new IntPoint(4, 4)));

            _world.tingRunner.CreateTing <Door>("Door2", new WorldCoordinate("DistantRoom", new IntPoint(3, 4)));
            door1.targetDoorName = "Door2";

            var pathfinder = new MimanPathfinder2(_world.tingRunner, _world.roomRunner);

            var result = pathfinder.Search(p1, p2);

            Assert.AreEqual(MimanPathStatus.FOUND_GOAL, result.status);
            Assert.AreEqual(1, result.tings.Length);
            Assert.AreEqual(door1, result.tings[0]);

            Console.WriteLine("RESULT: " + result.ToString());

            //var result2 = pathfinder.Search(p1, p2);
            //Assert.AreEqual(MimanPathStatus.FOUND_GOAL, result2.status);
        }
コード例 #2
0
        public void PathfindThroughElevator()
        {
            _eva.logger.AddListener(Console.WriteLine);

            SimpleRoomBuilder srb = new SimpleRoomBuilder(_world.roomRunner);

            srb.CreateRoomWithSize("DistantRoom", 10, 10);
            srb.CreateRoomWithSize("ElevatorRoom", 10, 10);

            // Add doors
            var elevatorDoor1    = _world.tingRunner.CreateTing <Door>("ElevatorDoor1", new WorldCoordinate("Eden", new IntPoint(4, 4)));
            var elevatorDoor2    = _world.tingRunner.CreateTing <Door>("ElevatorDoor2", new WorldCoordinate("DistantRoom", new IntPoint(3, 4)));
            var elevatorRoomDoor = _world.tingRunner.CreateTing <Door>("ElevatorRoomDoor", new WorldCoordinate("ElevatorRoom", new IntPoint(4, 4)));

            var p1 = _world.tingRunner.CreateTing <Point>("p1", new WorldCoordinate("Eden", new IntPoint(2, 4)));
            var p2 = _world.tingRunner.CreateTing <Point>("p2", new WorldCoordinate("DistantRoom", new IntPoint(4, 4)));

            var pathfinder = new MimanPathfinder2(_world.tingRunner, _world.roomRunner);
            var result     = pathfinder.Search(p1, p2);

            Console.WriteLine("Network at first:");
            var network = pathfinder.RecreateRoomNetwork();

            Console.WriteLine(network.ToString());

            Assert.AreEqual(MimanPathStatus.NO_PATH_FOUND, result.status);

            elevatorDoor1.targetDoorName = "ElevatorRoomDoor";
            elevatorDoor2.targetDoorName = "ElevatorRoomDoor";

            elevatorRoomDoor.elevatorAlternatives = new string[] { "ElevatorDoor1", "ElevatorDoor2" };
            elevatorRoomDoor.elevatorFloor        = 0;

            Console.WriteLine("Network after adding elevator alternatives:");
            var network2 = pathfinder.RecreateRoomNetwork();

            Console.WriteLine(network2.ToString());

            Console.WriteLine(" - second search - ");
            var result2 = pathfinder.Search(p1, p2);

            Assert.AreEqual(MimanPathStatus.FOUND_GOAL, result2.status);
        }
コード例 #3
0
ファイル: Main.cs プロジェクト: defc0n1/GameWorld2
        private static void SimplePathfinding()
        {
            D.onDLog += Console.WriteLine;             // take care of the D.Log message from invalid path

            InitialSaveFileCreator isc = new InitialSaveFileCreator();
            World world = new World(isc.CreateEmptyRelay());

            SimpleRoomBuilder srb = new SimpleRoomBuilder(world.roomRunner);

            srb.CreateRoomWithSize("Eden", 10, 10);
            var middleRoom  = srb.CreateRoomWithSize("MiddleRoom", 10, 10);
            var wrongRoom   = srb.CreateRoomWithSize("WrongRoom", 10, 10);
            var distantRoom = srb.CreateRoomWithSize("DistantRoom", 10, 10);

            middleRoom.worldPosition  = new IntPoint(10, 0);
            wrongRoom.worldPosition   = new IntPoint(30, 0);
            distantRoom.worldPosition = new IntPoint(50, 0);

            var p1 = world.tingRunner.CreateTing <Point>("p1", new WorldCoordinate("Eden", new IntPoint(2, 4)));
            var p2 = world.tingRunner.CreateTing <Point>("p2", new WorldCoordinate("DistantRoom", new IntPoint(4, 4)));

            // Add doors
            var edenDoor        = world.tingRunner.CreateTing <Door>("edenDoor", new WorldCoordinate("Eden", new IntPoint(4, 4)));
            var middleRoomDoor1 = world.tingRunner.CreateTing <Door>("middleRoomDoor1", new WorldCoordinate("MiddleRoom", new IntPoint(2, 4)));
            var middleRoomDoor2 = world.tingRunner.CreateTing <Door>("middleRoomDoor2", new WorldCoordinate("MiddleRoom", new IntPoint(7, 4)));
            var middleRoomDoor3 = world.tingRunner.CreateTing <Door>("middleRoomDoor3", new WorldCoordinate("MiddleRoom", new IntPoint(4, 4)));
            var wrongRoomDoor   = world.tingRunner.CreateTing <Door>("wrongRoomDoor", new WorldCoordinate("WrongRoom", new IntPoint(4, 4)));
            var distantRoomDoor = world.tingRunner.CreateTing <Door>("distantRoomDoor", new WorldCoordinate("DistantRoom", new IntPoint(2, 4)));

            edenDoor.targetDoorName        = "middleRoomDoor1";
            middleRoomDoor1.targetDoorName = "edenDoor";
            middleRoomDoor2.targetDoorName = "distantRoomDoor";
            middleRoomDoor3.targetDoorName = "wrongRoomDoor";
            wrongRoomDoor.targetDoorName   = "middleRoomDoor3";
            distantRoomDoor.targetDoorName = "middleRoomDoor2";

            world.sourceCodeDispenser.CreateSourceCodeFromString("OnDoorUsed", "");

            if (!world.isReadyToPlay)
            {
                foreach (string s in world.Preload())
                {
                }
            }

            var pathfinder = new MimanPathfinder2(world.tingRunner, world.roomRunner);

            var result = pathfinder.Search(p1, p2);

            Console.WriteLine("Result: " + result);
        }
コード例 #4
0
        public void LoopedDoorsPathfinding()
        {
            var world = CreateWorldWithSomeRooms();

            var edenDoor        = world.tingRunner.GetTing <Door>("edenDoor");
            var middleRoomDoor1 = world.tingRunner.GetTing <Door>("middleRoomDoor1");
            var middleRoomDoor2 = world.tingRunner.GetTing <Door>("middleRoomDoor2");
            var middleRoomDoor3 = world.tingRunner.GetTing <Door>("middleRoomDoor3");
            var wrongRoomDoor   = world.tingRunner.GetTing <Door>("wrongRoomDoor");
            var distantRoomDoor = world.tingRunner.GetTing <Door>("distantRoomDoor");

            //         EDEN <-> MIDDLE 1    MIDDLE 2 <-> WRONG
            //  DISTANT      <- MIDDLE 3

            edenDoor.targetDoorName        = middleRoomDoor1.name;
            middleRoomDoor1.targetDoorName = middleRoomDoor2.name;
            middleRoomDoor2.targetDoorName = wrongRoomDoor.name;
            middleRoomDoor3.targetDoorName = distantRoomDoor.name;
            wrongRoomDoor.targetDoorName   = edenDoor.name;

            var eden  = world.roomRunner.GetRoom("Eden");
            var mid   = world.roomRunner.GetRoom("MiddleRoom");
            var wrong = world.roomRunner.GetRoom("WrongRoom");
            var dist  = world.roomRunner.GetRoom("DistantRoom");

            eden.worldPosition  = new IntPoint(0, 0);
            mid.worldPosition   = new IntPoint(10, 0);
            wrong.worldPosition = new IntPoint(10, 0);
            dist.worldPosition  = new IntPoint(-2000, 0);

            var pathfinder = new MimanPathfinder2(world.tingRunner, world.roomRunner);
            var network    = pathfinder.RecreateRoomNetwork();

            Console.WriteLine(network.ToString());

            var p1 = world.tingRunner.CreateTing <Point>("p1", new WorldCoordinate("Eden", new IntPoint(2, 4)));
            var p2 = world.tingRunner.CreateTing <Point>("p2", new WorldCoordinate("DistantRoom", new IntPoint(4, 4)));

            var result = pathfinder.Search(p1, p2);

            Console.WriteLine("Result: " + result);

            Assert.AreEqual(MimanPathStatus.FOUND_GOAL, result.status);
            Assert.AreEqual(2, result.tings.Length);
            Assert.AreEqual("edenDoor", result.tings[0].name);
            Assert.AreEqual("middleRoomDoor3", result.tings[1].name);
        }
コード例 #5
0
        public void SimplePathfinding()
        {
            var world = CreateWorldWithSomeRooms();

            var pathfinder = new MimanPathfinder2(world.tingRunner, world.roomRunner);

            var network = pathfinder.RecreateRoomNetwork();

            Console.WriteLine(network.ToString());

            var p1 = world.tingRunner.CreateTing <Point>("p1", new WorldCoordinate("Eden", new IntPoint(2, 4)));
            var p2 = world.tingRunner.CreateTing <Point>("p2", new WorldCoordinate("DistantRoom", new IntPoint(4, 4)));

            var result = pathfinder.Search(p1, p2);

            Console.WriteLine("Result: " + result);

            Assert.AreEqual(MimanPathStatus.FOUND_GOAL, result.status);
            Assert.AreEqual(2, result.tings.Length);
            Assert.AreEqual("edenDoor", result.tings[0].name);
            Assert.AreEqual("middleRoomDoor2", result.tings[1].name);
        }
コード例 #6
0
ファイル: Main.cs プロジェクト: eriksvedang/GameWorld2
        private static void Eval(string[] pCommand)
        {
            Console.ForegroundColor = ConsoleColor.White;

            if (pCommand.Length == 0) {
                pCommand = new string[] { "m" };
            }

            int nrOfUpdates = 1;

            switch (pCommand[0]) {
            case "q":
            case "quit":
                _run = false;
                break;

            case "1":
                ChooseOption(0);
                break;

            case "2":
                ChooseOption(1);
                break;

            case "3":
                ChooseOption(2);
                break;

            case "4":
                ChooseOption(3);
                break;

            case "5":
                ChooseOption(4);
                break;

            case "6":
                ChooseOption(5);
                break;

            case "7":
                ChooseOption(6);
                break;

            case "PATH":
                var pathfinder = new MimanPathfinder2 (_world.tingRunner, _world.roomRunner);
                Ting sebastian = _world.tingRunner.GetTing ("Sebastian");
                Ting wellspringer = _world.tingRunner.GetTing ("Wellspringer");
                for (int i = 0; i < 100; i++) {
                    D.Log (" - " + i + " - ");
                    D.Log(pathfinder.Search (sebastian, wellspringer).ToString());
                }
                D.Log ("Did 100 searches.");
                break;

            case "clock":
                PrintClock();
                break;

            case "bn":
                BranchingDialogueNode branchingNode = _world.dialogueRunner.GetActiveBranchingDialogueNode(_focusedConversation);
                if (branchingNode != null) {
                    Console.WriteLine("On branching node " + branchingNode.name + " in conversation " + branchingNode.conversation);
                } else {
                    Console.WriteLine("Not on a branching node");
                }
                break;

            case "occupants":
                Room r = _world.roomRunner.GetRoom (pCommand [1]);
                foreach (var tile in r.tiles) {
                    D.Log (tile.ToString () + ": " + tile.GetOccupantsAsString());
                }
                break;

            case "t":
            case "tick":
                nrOfUpdates = 1;
                if (pCommand.Length > 1) {
                    nrOfUpdates = Convert.ToInt32(pCommand[1]);
                }
                for (int i = 0; i < nrOfUpdates; i++) {
                    _world.Update(NORMAL_DELTA_TIME);
                    if (!_autoPilot) {
                        PrintTotalWorldTime();
                    }
                }
                break;

            case "ff": // fast forward
                DateTime startTime = DateTime.Now;
                nrOfUpdates = (int)FPS;
                if (pCommand.Length > 1) {
                    nrOfUpdates = Convert.ToInt32(pCommand[1]) * (int)FPS;
                }
                for (int i = 0; i < nrOfUpdates; i++) {
                    _world.Update(NORMAL_DELTA_TIME);
                }
                PrintTotalWorldTime();
                double totalLength = (DateTime.Now - startTime).TotalSeconds;
                float secsPerUpdate = (float)(totalLength / (double)nrOfUpdates);
                float updatesPerSec = 1f / secsPerUpdate;
                Console.WriteLine("ff took " + (float)totalLength + "s. (" + secsPerUpdate + " s/update, " + updatesPerSec + " updates/s)");
                break;

            case "->": // smart fast forward
                SmartFastForward(pCommand);
                break;

            case "!":
            case "run": // run Grimm script
                RunGrimmScript(pCommand, 1);
                break;

            case "dump":
                Console.WriteLine(_world.tingRunner.ToString());
                Console.WriteLine (_world.roomRunner.ToString());
                Console.WriteLine(_world.dialogueRunner.ToString());
                Console.WriteLine(_world.programRunner.ToString());
                Console.WriteLine(_world.sourceCodeDispenser.ToString());
                Console.WriteLine(_world.timetableRunner.ToString());
                break;

            case "book":
                // turn all the dialogue into a file called book.txt
                string text = _world.dialogueRunner.GetAllDialogueAsString();
                var file = File.CreateText("book.txt");
                file.Write(text);
                file.Close();
                Console.WriteLine("Saved all dialogue to book.txt");
                break;

            case "i":
            case "info":
                string tingName = "Sebastian";
                if (pCommand.Length > 1) {
                    tingName = pCommand[1];
                }
                MimanTing ting = _world.tingRunner.GetTing<MimanTing>(tingName);
                PrintTingInfo(ting);
                break;

            case "pp":
                string tingName2 = "Sebastian";
                if (pCommand.Length > 1) {
                    tingName2 = pCommand [1];
                }
                Character character = _world.tingRunner.GetTing<Character> (tingName2);
                if (character != null) {
                    Console.WriteLine (character.PrettyPrintableInfo ());
                } else {
                    Console.WriteLine ("Not a character");
                }
                break;

            case "ppall":
                foreach(var c in _world.tingRunner.GetTingsOfType<Character>()) {
                    Console.WriteLine(c.name + "\t" + c.PrettyPrintableInfo());
                }
                break;

            case "m":
            case "macro":
                ExecuteMacro();
                break;

            case "progs":
                foreach(var prog in _world.programRunner.GetAllPrograms()) {
                    Console.WriteLine ("- " + prog);
                }
                break;

            case "h":
            case "help":
                Console.WriteLine("q / quit \ni / info [TING] \ndump (prints runners) \n! / run [GRIMM COMMANDO] \nclock (prints in game clock) \nt / tick [N] (ticks N steps) \nff [N] (fast forwards N seconds, does not print time stamp) \nauto_answer [ON | OFF] (choose answers automatically in conversations) \nload/save \nlog [TING]\nconvos (list all active conversations) \nbook save a book.txt file with all dialogue \nroom [TING (optional)] list all chracters in the same room as the ting, no arg means avatar \n@ [TING] translates to avatarName.Interact(TING) and ff until the interaction event\npp [character] pretty print info about character\nppall pretty print info about all characters\n\nprogs print all program names");
                break;

            case "save":
                _world.Save("save.json");
                break;

            case "load":
                Reset();
                _world = new World("save.json");
                LoadTranslationFiles();
                foreach (string s in _world.Preload()) {
                    //Console.WriteLine(s);
                }
                SetupWorldListeners();
                break;

            case "log":
                Ting t = _world.tingRunner.GetTing(pCommand[1]);
                t.logger.AddListener(Console.WriteLine);
                break;

            case "convos":
                var activeConversations = _world.dialogueRunner.GetActiveConversations();
                foreach (var convo in activeConversations) {
                    Console.WriteLine(" " + convo);
                }
                break;

            case "room":
                PrintRoomTings(pCommand);
                break;

            case "@":
                FastInteract(pCommand);
                break;

            case "auto_answer":
                _autoAnswer = true;
                if (pCommand.Length > 1) {
                    if(pCommand[1].ToString().ToLower() == "off") {
                        _autoAnswer = false;
                    }
                }
                Console.WriteLine("Auto answer: " + (_autoAnswer ? "ON" : "OFF"));
                break;

            case "stop":
                Console.WriteLine("Stopped by command 'stop'");
                _run = false;
                break;

            default:
                //Console.WriteLine("Can't understand command '" + pCommand[0] + "'");
                RunGrimmScript(pCommand, 0);

                break;
            }
        }
コード例 #7
0
ファイル: Main.cs プロジェクト: eriksvedang/GameWorld2
        private static void SimplePathfinding()
        {
            D.onDLog += Console.WriteLine; // take care of the D.Log message from invalid path

            InitialSaveFileCreator isc = new InitialSaveFileCreator();
            World world = new World(isc.CreateEmptyRelay());

            SimpleRoomBuilder srb = new SimpleRoomBuilder(world.roomRunner);
            srb.CreateRoomWithSize("Eden", 10, 10);
            var middleRoom = srb.CreateRoomWithSize("MiddleRoom", 10, 10);
            var wrongRoom = srb.CreateRoomWithSize("WrongRoom", 10, 10);
            var distantRoom = srb.CreateRoomWithSize("DistantRoom", 10, 10);

            middleRoom.worldPosition = new IntPoint(10, 0);
            wrongRoom.worldPosition = new IntPoint(30, 0);
            distantRoom.worldPosition = new IntPoint(50, 0);

            var p1 = world.tingRunner.CreateTing<Point>("p1", new WorldCoordinate("Eden", new IntPoint(2, 4)));
            var p2 = world.tingRunner.CreateTing<Point>("p2", new WorldCoordinate("DistantRoom", new IntPoint(4, 4)));

            // Add doors
            var edenDoor = world.tingRunner.CreateTing<Door>("edenDoor", new WorldCoordinate("Eden", new IntPoint(4, 4)));
            var middleRoomDoor1 = world.tingRunner.CreateTing<Door>("middleRoomDoor1", new WorldCoordinate("MiddleRoom", new IntPoint(2, 4)));
            var middleRoomDoor2 = world.tingRunner.CreateTing<Door>("middleRoomDoor2", new WorldCoordinate("MiddleRoom", new IntPoint(7, 4)));
            var middleRoomDoor3 = world.tingRunner.CreateTing<Door>("middleRoomDoor3", new WorldCoordinate("MiddleRoom", new IntPoint(4, 4)));
            var wrongRoomDoor = world.tingRunner.CreateTing<Door>("wrongRoomDoor", new WorldCoordinate("WrongRoom", new IntPoint(4, 4)));
            var distantRoomDoor = world.tingRunner.CreateTing<Door>("distantRoomDoor", new WorldCoordinate("DistantRoom", new IntPoint(2, 4)));

            edenDoor.targetDoorName = "middleRoomDoor1";
            middleRoomDoor1.targetDoorName = "edenDoor";
            middleRoomDoor2.targetDoorName = "distantRoomDoor";
            middleRoomDoor3.targetDoorName = "wrongRoomDoor";
            wrongRoomDoor.targetDoorName = "middleRoomDoor3";
            distantRoomDoor.targetDoorName = "middleRoomDoor2";

            world.sourceCodeDispenser.CreateSourceCodeFromString ("OnDoorUsed", "");

            if(!world.isReadyToPlay) {
                foreach (string s in world.Preload()) {}
            }

            var pathfinder = new MimanPathfinder2(world.tingRunner, world.roomRunner);

            var result = pathfinder.Search(p1, p2);
            Console.WriteLine("Result: " + result);
        }
コード例 #8
0
ファイル: Main.cs プロジェクト: eriksvedang/GameWorld2
        private static void ProfileMimanPathfinding(int worldSize)
        {
            D.onDLog += Console.WriteLine;

            InitialSaveFileCreator isc = new InitialSaveFileCreator();
            World world = new World(isc.CreateEmptyRelay());

            SimpleRoomBuilder srb = new SimpleRoomBuilder(world.roomRunner);

            int worldWidth = worldSize;
            int worldHeight = worldSize;
            int roomSize = 10;

            int tingCounter = 0;

            for (int x = 0; x <= worldWidth; x++) {
                for (int y = 0; y <= worldHeight; y++) {
                    Room r = srb.CreateRoomWithSize("Room_" + x + "_" + y, roomSize, roomSize);

                    Door door1 = world.tingRunner.CreateTing<Door> (r.name + "_Door1", new WorldCoordinate (r.name, new IntPoint (0, 0)));
                    Door door2 = world.tingRunner.CreateTing<Door> (r.name + "_Door2", new WorldCoordinate (r.name, new IntPoint (roomSize - 1, roomSize - 1)));
                    door1.direction = Direction.DOWN;
                    door2.direction = Direction.UP;

                    // Randomizer.GetIntValue (0, roomSize);

                    int rx1 = (x + 1) % worldWidth;
                    int ry1 = y;
                    door1.targetDoorName = "Room_" + rx1 + "_" + ry1 + "_Door2";

                    int rx2 = x;
                    int ry2 = (y + 1) % worldHeight;
                    door2.targetDoorName = "Room_" + rx2 + "_" + ry2 + "_Door1";

                    world.tingRunner.CreateTing<Point> ("Point_" + (tingCounter++), new WorldCoordinate (r.name, new IntPoint (roomSize / 2, roomSize / 2)));

                    r.worldPosition = new IntPoint(x * roomSize + Randomizer.GetIntValue(-3, 3),
                                                   y * roomSize + Randomizer.GetIntValue(-3, 3));
                }
            }

            world.sourceCodeDispenser.CreateSourceCodeFromString ("OnDoorUsed", "");

            if(!world.isReadyToPlay) {
                foreach (string s in world.Preload())
                {
                    //Console.WriteLine(s);
                }
            }

            Console.WriteLine ("Room runner stats: " + world.roomRunner.ToString ());

            var pathfinder = new MimanPathfinder2 (world.tingRunner, world.roomRunner);

            for (int i = 0; i < 100; i++) {
                Point start = world.tingRunner.GetTing<Point> ("Point_" + Randomizer.GetIntValue (0, tingCounter));
                Point goal = world.tingRunner.GetTing<Point> ("Point_" + Randomizer.GetIntValue (0, tingCounter));
                var result = pathfinder.Search (start, goal);
                Console.WriteLine (result.status);
            }
        }
コード例 #9
0
ファイル: Computer.cs プロジェクト: eriksvedang/GameWorld2
        public object[] API_FindPath(string start, string goal)
        {
            _computer.API_Sleep (Randomizer.GetValue (1f, 4f));

            Ting startT = _tingRunner.GetTingUnsafe(start);
            Ting goalT = _tingRunner.GetTingUnsafe(goal);

            if(startT == null) {
                _computer.API_Print("Can't find start object");
                return new object[] {};
            }
            if(goalT == null) {
                _computer.API_Print("Can't find goal object");
                return new object[] {};
            }
            var pathFinder = new MimanPathfinder2(_tingRunner, _roomRunner);
            MimanPath path = pathFinder.Search(startT, goalT);

            return path.tings.Select(t => t.room.name).ToArray();
        }
コード例 #10
0
ファイル: Main.cs プロジェクト: defc0n1/GameWorld2
        private static void Eval(string[] pCommand)
        {
            Console.ForegroundColor = ConsoleColor.White;

            if (pCommand.Length == 0)
            {
                pCommand = new string[] { "m" };
            }

            int nrOfUpdates = 1;

            switch (pCommand[0])
            {
            case "q":
            case "quit":
                _run = false;
                break;

            case "1":
                ChooseOption(0);
                break;

            case "2":
                ChooseOption(1);
                break;

            case "3":
                ChooseOption(2);
                break;

            case "4":
                ChooseOption(3);
                break;

            case "5":
                ChooseOption(4);
                break;

            case "6":
                ChooseOption(5);
                break;

            case "7":
                ChooseOption(6);
                break;

            case "PATH":
                var  pathfinder   = new MimanPathfinder2(_world.tingRunner, _world.roomRunner);
                Ting sebastian    = _world.tingRunner.GetTing("Sebastian");
                Ting wellspringer = _world.tingRunner.GetTing("Wellspringer");
                for (int i = 0; i < 100; i++)
                {
                    D.Log(" - " + i + " - ");
                    D.Log(pathfinder.Search(sebastian, wellspringer).ToString());
                }
                D.Log("Did 100 searches.");
                break;

            case "clock":
                PrintClock();
                break;

            case "bn":
                BranchingDialogueNode branchingNode = _world.dialogueRunner.GetActiveBranchingDialogueNode(_focusedConversation);
                if (branchingNode != null)
                {
                    Console.WriteLine("On branching node " + branchingNode.name + " in conversation " + branchingNode.conversation);
                }
                else
                {
                    Console.WriteLine("Not on a branching node");
                }
                break;

            case "occupants":
                Room r = _world.roomRunner.GetRoom(pCommand [1]);
                foreach (var tile in r.tiles)
                {
                    D.Log(tile.ToString() + ": " + tile.GetOccupantsAsString());
                }
                break;

            case "t":
            case "tick":
                nrOfUpdates = 1;
                if (pCommand.Length > 1)
                {
                    nrOfUpdates = Convert.ToInt32(pCommand[1]);
                }
                for (int i = 0; i < nrOfUpdates; i++)
                {
                    _world.Update(NORMAL_DELTA_TIME);
                    if (!_autoPilot)
                    {
                        PrintTotalWorldTime();
                    }
                }
                break;

            case "ff":             // fast forward
                DateTime startTime = DateTime.Now;
                nrOfUpdates = (int)FPS;
                if (pCommand.Length > 1)
                {
                    nrOfUpdates = Convert.ToInt32(pCommand[1]) * (int)FPS;
                }
                for (int i = 0; i < nrOfUpdates; i++)
                {
                    _world.Update(NORMAL_DELTA_TIME);
                }
                PrintTotalWorldTime();
                double totalLength   = (DateTime.Now - startTime).TotalSeconds;
                float  secsPerUpdate = (float)(totalLength / (double)nrOfUpdates);
                float  updatesPerSec = 1f / secsPerUpdate;
                Console.WriteLine("ff took " + (float)totalLength + "s. (" + secsPerUpdate + " s/update, " + updatesPerSec + " updates/s)");
                break;

            case "->":             // smart fast forward
                SmartFastForward(pCommand);
                break;

            case "!":
            case "run":             // run Grimm script
                RunGrimmScript(pCommand, 1);
                break;

            case "dump":
                Console.WriteLine(_world.tingRunner.ToString());
                Console.WriteLine(_world.roomRunner.ToString());
                Console.WriteLine(_world.dialogueRunner.ToString());
                Console.WriteLine(_world.programRunner.ToString());
                Console.WriteLine(_world.sourceCodeDispenser.ToString());
                Console.WriteLine(_world.timetableRunner.ToString());
                break;

            case "book":
                // turn all the dialogue into a file called book.txt
                string text = _world.dialogueRunner.GetAllDialogueAsString();
                var    file = File.CreateText("book.txt");
                file.Write(text);
                file.Close();
                Console.WriteLine("Saved all dialogue to book.txt");
                break;

            case "i":
            case "info":
                string tingName = "Sebastian";
                if (pCommand.Length > 1)
                {
                    tingName = pCommand[1];
                }
                MimanTing ting = _world.tingRunner.GetTing <MimanTing>(tingName);
                PrintTingInfo(ting);
                break;

            case "pp":
                string tingName2 = "Sebastian";
                if (pCommand.Length > 1)
                {
                    tingName2 = pCommand [1];
                }
                Character character = _world.tingRunner.GetTing <Character> (tingName2);
                if (character != null)
                {
                    Console.WriteLine(character.PrettyPrintableInfo());
                }
                else
                {
                    Console.WriteLine("Not a character");
                }
                break;

            case "ppall":
                foreach (var c in _world.tingRunner.GetTingsOfType <Character>())
                {
                    Console.WriteLine(c.name + "\t" + c.PrettyPrintableInfo());
                }
                break;

            case "m":
            case "macro":
                ExecuteMacro();
                break;

            case "progs":
                foreach (var prog in _world.programRunner.GetAllPrograms())
                {
                    Console.WriteLine("- " + prog);
                }
                break;

            case "h":
            case "help":
                Console.WriteLine("q / quit \ni / info [TING] \ndump (prints runners) \n! / run [GRIMM COMMANDO] \nclock (prints in game clock) \nt / tick [N] (ticks N steps) \nff [N] (fast forwards N seconds, does not print time stamp) \nauto_answer [ON | OFF] (choose answers automatically in conversations) \nload/save \nlog [TING]\nconvos (list all active conversations) \nbook save a book.txt file with all dialogue \nroom [TING (optional)] list all chracters in the same room as the ting, no arg means avatar \n@ [TING] translates to avatarName.Interact(TING) and ff until the interaction event\npp [character] pretty print info about character\nppall pretty print info about all characters\n\nprogs print all program names");
                break;

            case "save":
                _world.Save("save.json");
                break;

            case "load":
                Reset();
                _world = new World("save.json");
                LoadTranslationFiles();
                foreach (string s in _world.Preload())
                {
                    //Console.WriteLine(s);
                }
                SetupWorldListeners();
                break;

            case "log":
                Ting t = _world.tingRunner.GetTing(pCommand[1]);
                t.logger.AddListener(Console.WriteLine);
                break;

            case "convos":
                var activeConversations = _world.dialogueRunner.GetActiveConversations();
                foreach (var convo in activeConversations)
                {
                    Console.WriteLine(" " + convo);
                }
                break;

            case "room":
                PrintRoomTings(pCommand);
                break;

            case "@":
                FastInteract(pCommand);
                break;

            case "auto_answer":
                _autoAnswer = true;
                if (pCommand.Length > 1)
                {
                    if (pCommand[1].ToString().ToLower() == "off")
                    {
                        _autoAnswer = false;
                    }
                }
                Console.WriteLine("Auto answer: " + (_autoAnswer ? "ON" : "OFF"));
                break;

            case "stop":
                Console.WriteLine("Stopped by command 'stop'");
                _run = false;
                break;

            default:
                //Console.WriteLine("Can't understand command '" + pCommand[0] + "'");
                RunGrimmScript(pCommand, 0);

                break;
            }
        }
コード例 #11
0
ファイル: Main.cs プロジェクト: defc0n1/GameWorld2
        private static void ProfileMimanPathfinding(int worldSize)
        {
            D.onDLog += Console.WriteLine;

            InitialSaveFileCreator isc = new InitialSaveFileCreator();
            World world = new World(isc.CreateEmptyRelay());

            SimpleRoomBuilder srb = new SimpleRoomBuilder(world.roomRunner);

            int worldWidth  = worldSize;
            int worldHeight = worldSize;
            int roomSize    = 10;

            int tingCounter = 0;

            for (int x = 0; x <= worldWidth; x++)
            {
                for (int y = 0; y <= worldHeight; y++)
                {
                    Room r = srb.CreateRoomWithSize("Room_" + x + "_" + y, roomSize, roomSize);

                    Door door1 = world.tingRunner.CreateTing <Door> (r.name + "_Door1", new WorldCoordinate(r.name, new IntPoint(0, 0)));
                    Door door2 = world.tingRunner.CreateTing <Door> (r.name + "_Door2", new WorldCoordinate(r.name, new IntPoint(roomSize - 1, roomSize - 1)));
                    door1.direction = Direction.DOWN;
                    door2.direction = Direction.UP;

                    // Randomizer.GetIntValue (0, roomSize);

                    int rx1 = (x + 1) % worldWidth;
                    int ry1 = y;
                    door1.targetDoorName = "Room_" + rx1 + "_" + ry1 + "_Door2";

                    int rx2 = x;
                    int ry2 = (y + 1) % worldHeight;
                    door2.targetDoorName = "Room_" + rx2 + "_" + ry2 + "_Door1";

                    world.tingRunner.CreateTing <Point> ("Point_" + (tingCounter++), new WorldCoordinate(r.name, new IntPoint(roomSize / 2, roomSize / 2)));

                    r.worldPosition = new IntPoint(x * roomSize + Randomizer.GetIntValue(-3, 3),
                                                   y * roomSize + Randomizer.GetIntValue(-3, 3));
                }
            }

            world.sourceCodeDispenser.CreateSourceCodeFromString("OnDoorUsed", "");

            if (!world.isReadyToPlay)
            {
                foreach (string s in world.Preload())
                {
                    //Console.WriteLine(s);
                }
            }

            Console.WriteLine("Room runner stats: " + world.roomRunner.ToString());

            var pathfinder = new MimanPathfinder2(world.tingRunner, world.roomRunner);

            for (int i = 0; i < 100; i++)
            {
                Point start  = world.tingRunner.GetTing <Point> ("Point_" + Randomizer.GetIntValue(0, tingCounter));
                Point goal   = world.tingRunner.GetTing <Point> ("Point_" + Randomizer.GetIntValue(0, tingCounter));
                var   result = pathfinder.Search(start, goal);
                Console.WriteLine(result.status);
            }
        }
コード例 #12
0
        public void SimplePathfinding()
        {
            var world = CreateWorldWithSomeRooms();

            var pathfinder = new MimanPathfinder2(world.tingRunner, world.roomRunner);

            var network = pathfinder.RecreateRoomNetwork();
            Console.WriteLine(network.ToString());

            var p1 = world.tingRunner.CreateTing<Point>("p1", new WorldCoordinate("Eden", new IntPoint(2, 4)));
            var p2 = world.tingRunner.CreateTing<Point>("p2", new WorldCoordinate("DistantRoom", new IntPoint(4, 4)));

            var result = pathfinder.Search(p1, p2);
            Console.WriteLine("Result: " + result);

            Assert.AreEqual(MimanPathStatus.FOUND_GOAL, result.status);
            Assert.AreEqual(2, result.tings.Length);
            Assert.AreEqual("edenDoor", result.tings[0].name);
            Assert.AreEqual("middleRoomDoor2", result.tings[1].name);
        }
コード例 #13
0
        public void PathfindToOtherRoom()
        {
            MimanPathfinder2.ClearRoomNetwork();

            //D.onDLog += Console.WriteLine; // take care of the D.Log message from invalid path
            _eva.logger.AddListener(Console.WriteLine);

            SimpleRoomBuilder srb = new SimpleRoomBuilder(_world.roomRunner);
            srb.CreateRoomWithSize("DistantRoom", 10, 10);

            var p1 = _world.tingRunner.CreateTing<Point>("p1", new WorldCoordinate("Eden", new IntPoint(2, 4)));
            var p2 = _world.tingRunner.CreateTing<Point>("p2", new WorldCoordinate("DistantRoom", new IntPoint(4, 4)));

            // Add doors
            var door1 = _world.tingRunner.CreateTing<Door>("Door1", new WorldCoordinate("Eden", new IntPoint(4, 4)));
            _world.tingRunner.CreateTing<Door>("Door2", new WorldCoordinate("DistantRoom", new IntPoint(3, 4)));
            door1.targetDoorName = "Door2";

            var pathfinder = new MimanPathfinder2(_world.tingRunner, _world.roomRunner);

            var result = pathfinder.Search(p1, p2);
            Assert.AreEqual(MimanPathStatus.FOUND_GOAL, result.status);
            Assert.AreEqual(1, result.tings.Length);
            Assert.AreEqual(door1, result.tings[0]);

            Console.WriteLine("RESULT: " + result.ToString());

            //var result2 = pathfinder.Search(p1, p2);
            //Assert.AreEqual(MimanPathStatus.FOUND_GOAL, result2.status);
        }
コード例 #14
0
        public void PathfindThroughElevator()
        {
            _eva.logger.AddListener(Console.WriteLine);

            SimpleRoomBuilder srb = new SimpleRoomBuilder(_world.roomRunner);
            srb.CreateRoomWithSize("DistantRoom", 10, 10);
            srb.CreateRoomWithSize("ElevatorRoom", 10, 10);

            // Add doors
            var elevatorDoor1 = _world.tingRunner.CreateTing<Door>("ElevatorDoor1", new WorldCoordinate("Eden", new IntPoint(4, 4)));
            var elevatorDoor2 = _world.tingRunner.CreateTing<Door>("ElevatorDoor2", new WorldCoordinate("DistantRoom", new IntPoint(3, 4)));
            var elevatorRoomDoor = _world.tingRunner.CreateTing<Door>("ElevatorRoomDoor", new WorldCoordinate("ElevatorRoom", new IntPoint(4, 4)));

            var p1 = _world.tingRunner.CreateTing<Point>("p1", new WorldCoordinate("Eden", new IntPoint(2, 4)));
            var p2 = _world.tingRunner.CreateTing<Point>("p2", new WorldCoordinate("DistantRoom", new IntPoint(4, 4)));

            var pathfinder = new MimanPathfinder2(_world.tingRunner, _world.roomRunner);
            var result = pathfinder.Search(p1, p2);

            Console.WriteLine("Network at first:");
            var network = pathfinder.RecreateRoomNetwork();
            Console.WriteLine(network.ToString());

            Assert.AreEqual(MimanPathStatus.NO_PATH_FOUND, result.status);

            elevatorDoor1.targetDoorName = "ElevatorRoomDoor";
            elevatorDoor2.targetDoorName = "ElevatorRoomDoor";

            elevatorRoomDoor.elevatorAlternatives = new string[] { "ElevatorDoor1", "ElevatorDoor2" };
            elevatorRoomDoor.elevatorFloor = 0;

            Console.WriteLine("Network after adding elevator alternatives:");
            var network2 = pathfinder.RecreateRoomNetwork();
            Console.WriteLine(network2.ToString());

            Console.WriteLine(" - second search - ");
            var result2 = pathfinder.Search(p1, p2);

            Assert.AreEqual(MimanPathStatus.FOUND_GOAL, result2.status);
        }
コード例 #15
0
        public void LoopedDoorsPathfindingLoopInStartRoom()
        {
            var world = CreateWorldWithSomeRooms();

            var edenDoor = world.tingRunner.GetTing<Door>("edenDoor");
            var middleRoomDoor1 = world.tingRunner.GetTing<Door>("middleRoomDoor1");
            var middleRoomDoor2 = world.tingRunner.GetTing<Door>("middleRoomDoor2");
            var middleRoomDoor3 = world.tingRunner.GetTing<Door>("middleRoomDoor3");
            var wrongRoomDoor = world.tingRunner.GetTing<Door>("wrongRoomDoor");
            //var distantRoomDoor = world.tingRunner.GetTing<Door>("distantRoomDoor");

            middleRoomDoor1.targetDoorName = middleRoomDoor2.name;
            middleRoomDoor2.targetDoorName = wrongRoomDoor.name;
            middleRoomDoor3.targetDoorName = middleRoomDoor2.name;
            wrongRoomDoor.targetDoorName = edenDoor.name;

            var eden = world.roomRunner.GetRoom("Eden");
            var mid = world.roomRunner.GetRoom("MiddleRoom");
            var wrong = world.roomRunner.GetRoom("WrongRoom");
            var dist = world.roomRunner.GetRoom("DistantRoom");

            mid.worldPosition = new IntPoint(0,0);
            wrong.worldPosition = new IntPoint(100,0);
            eden.worldPosition = new IntPoint(-200,0);
            dist.worldPosition = new IntPoint(200,0);

            var pathfinder = new MimanPathfinder2(world.tingRunner, world.roomRunner);
            var network = pathfinder.RecreateRoomNetwork();
            Console.WriteLine(network.ToString());

            var p1 = world.tingRunner.CreateTing<Point>("p1", new WorldCoordinate("MiddleRoom", new IntPoint(2, 4)));
            var p2 = world.tingRunner.CreateTing<Point>("p2", new WorldCoordinate("Eden", new IntPoint(4, 4)));

            var result = pathfinder.Search(p1, p2);
            Console.WriteLine("Result: " + result);

            Assert.AreEqual(MimanPathStatus.FOUND_GOAL, result.status);
            Assert.AreEqual(2, result.tings.Length);
            Assert.AreEqual("middleRoomDoor2", result.tings[0].name);
            Assert.AreEqual("wrongRoomDoor", result.tings[1].name);
        }