public static void GenerateInitData()
        {
            InitialSaveFileCreator i = new InitialSaveFileCreator();
            World world = new World(i.CreateEmptyRelay());

            SimpleRoomBuilder srb = new SimpleRoomBuilder(world.roomRunner);
            srb.CreateRoomWithSize("Eden", 5, 5);
            srb.CreateRoomWithSize("Hallway", 5, 5);
            srb.CreateRoomWithSize("Kitchen", 10, 5);
            srb.CreateRoomWithSize("Bedroom", 5, 5);

            world.tingRunner.CreateTing<Character>("Adam", new WorldCoordinate("Eden", new IntPoint(0, 0)));
            world.tingRunner.CreateTing<Character>("Eva", new WorldCoordinate("Eden", new IntPoint(4, 4)));

            MysticalCube c = world.tingRunner.CreateTing<MysticalCube>("PowerCube", new WorldCoordinate("Eden", new IntPoint(2, 2)));
            c.onInteractionSourceCodeName = "PowerCube";

            world.relay.SaveTableSubsetSeparately(Room.TABLE_NAME, INIT_DATA_PATH + "Rooms.json");
            RelayLib.RelayTwo tingSubset = new RelayLib.RelayTwo();

            foreach(string table in world.tingRunner.loadedTingTables)
                tingSubset.MergeWith(world.relay.Subset(table, (o) => { return true; }));

            tingSubset.SaveAll(INIT_DATA_PATH + "Tings.json");
        }
Exemple #2
0
        public override void Init()
        {
            base.Init ();

            // Ensure inventory room
            if(!_roomRunner.HasRoom(inventoryRoomName)) {
                SimpleRoomBuilder srb = new SimpleRoomBuilder(_roomRunner);
                srb.CreateRoomWithSize(inventoryRoomName, 5, 4);
            }
        }
Exemple #3
0
        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);
        }
Exemple #4
0
        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);
            }
        }
Exemple #5
0
		public void CreatingRoomConveniently()
		{
			RelayTwo relay = new RelayTwo();
			relay.CreateTable(Room.TABLE_NAME);
			RoomRunner roomRunner = new RoomRunner(relay);
			
			SimpleRoomBuilder srb = new SimpleRoomBuilder(roomRunner);
			Room closet = srb.CreateRoomWithSize("Closet", 4, 3);
			Assert.AreEqual(12, closet.tiles.Length);
			
			for(int x = 0; x < 4; x++)
			{
				for(int y = 0; y < 3; y++)
				{
					Assert.IsNotNull(closet.GetTile(new IntPoint(x, y)));
				}
			}
		}
        World CreateWorldWithSomeRooms()
        {
            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);

            // 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";

            var distantTile = new PointTileNode(new IntPoint(200, 200), wrongRoom);
            distantTile.group = 1;
            wrongRoom.AddTile(distantTile);

            var wrongRoomUnattachedDoor = world.tingRunner.CreateTing<Door>("wrongRoomUnattachedDoor", new WorldCoordinate("WrongRoom", new IntPoint(200, 200)));
            wrongRoomUnattachedDoor.targetDoorName = "edenDoor";

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

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

            return world;
        }
        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);
        }
        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);
        }
        public void NoValidPath()
        {
            const string unreachableRoomName = "UnreachableRoom";

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

            D.onDLog += Console.WriteLine; // take care of the D.Log message from invalid path
            _eva.position = new WorldCoordinate("Eden", new IntPoint(2, 3));
            _eva.WalkTo(new WorldCoordinate(unreachableRoomName, new IntPoint(5, 7)));

            WorldTestHelper.UpdateWorld(_world, 1f);
            Assert.AreEqual("", _eva.actionName);
            Assert.AreEqual(new WorldCoordinate("Eden", new IntPoint(2, 3)), _eva.position);
        }
Exemple #10
0
        public override void Init()
        {
            base.Init ();

            // Ensure inventory room
            if(!_roomRunner.HasRoom(inventoryRoomName)) {
                SimpleRoomBuilder srb = new SimpleRoomBuilder(_roomRunner);
                srb.CreateRoomWithSize(inventoryRoomName, 1, 1);
            }

            if(timetableName != "") {
                RefreshTimetable();
            }
        }