Exemplo n.º 1
0
        public void FindPathInOneRoom()
        {
            Room[] rooms = LoadFromFile();
            PrintWorld(rooms, Path<TileNode>.EMPTY);
            TileNode start = null, goal = null;

            foreach (Room r in rooms) {
                GameTypes.IntPoint localStart = r.WorldToLocalPoint(new GameTypes.IntPoint(-8, 1));
                GameTypes.IntPoint localGoal = r.WorldToLocalPoint(new GameTypes.IntPoint(-1, 6));

                if (r.GetTileType(localStart) == TileType.FLOOR) {
                    start = r.GetTile(localStart);
                }

                if (r.GetTileType(localGoal) == TileType.FLOOR) {
                    goal = r.GetTile(localGoal);
                }

            }

            Assert.NotNull(start);
            Assert.NotNull(goal);
            PathSolver<TileNode> solver = new PathSolver<TileNode>();
            MultiRoomNetwork roomNetwork = new MultiRoomNetwork(rooms);
            var foundPath = solver.FindPath(start, goal, roomNetwork);
            Assert.AreEqual(PathStatus.FOUND_GOAL, foundPath.status);
            PrintWorld(rooms, foundPath);
        }
Exemplo n.º 2
0
        public void FindImpossiblePath()
        {
            Room[] rooms = LoadFromFile();
            PrintWorld(rooms, Path<TileNode>.EMPTY);
            TileNode start = null, goal = null;

            foreach (Room r in rooms) {
                GameTypes.IntPoint localStart = r.WorldToLocalPoint(new GameTypes.IntPoint(-8, 1));
                GameTypes.IntPoint localGoal = r.WorldToLocalPoint(new GameTypes.IntPoint(13, 4));

                if (r.GetTileType(localStart) == TileType.FLOOR) {
                    start = r.GetTile(localStart);
                }

                if (r.GetTileType(localGoal) == TileType.FLOOR) {
                    goal = r.GetTile(localGoal);
                }

            }

            Assert.NotNull(start);
            Assert.NotNull(goal);
            PathSolver<TileNode> solver = new PathSolver<TileNode>();
            MultiRoomNetwork roomNetwork = new MultiRoomNetwork(rooms);
            var foundPath = solver.FindPath(start, goal, roomNetwork, true);
            Assert.AreEqual(PathStatus.DESTINATION_UNREACHABLE, foundPath.status);
            PrintWorld(rooms, foundPath);
        }
Exemplo n.º 3
0
 static void SpeedTest(string maze, int width, int height, int iterations)
 {
     var network = new SamplePathNetwork(maze, width, height);
     var solver = new PathSolver<SampleNode>();
     for (int i = 0; i < iterations; i++) {
         IPathNode start = network.GetNode(rand.Next(width), rand.Next(height));
         IPathNode goal = network.GetNode(rand.Next(width), rand.Next(height));
         Path<SampleNode> p = solver.FindPath(start, goal, network, true);
         Console.WriteLine(p.status.ToString());
     }
 }
Exemplo n.º 4
0
		public void BasicUsage()
		{
			{
				RelayTwo relay = new RelayTwo();
				relay.CreateTable(Room.TABLE_NAME);
				RoomRunner roomRunner = new RoomRunner(relay);
                foreach (string s in roomRunner.Preload()) ;

				Room r1 = roomRunner.CreateRoom<Room>("r1");

                PointTileNode door1 = null;
				
				for(int i = 0; i < 100; i++)
				{
					int x = i % 10;
					int y = i / 10;
					
					if(x == 9 && y == 9) {
                        door1 = new PointTileNode(new IntPoint(9, 9), r1);
                        r1.AddTile(door1);
					}
					else {
                        r1.AddTile(new PointTileNode(new IntPoint(x, y), r1 ));
					}
				}

				r1.worldPosition = new IntPoint(50, 0);

				relay.SaveAll("room_test.json");
			}
			
			{
                RelayTwo relay = new RelayTwo("room_test.json");
				RoomRunner roomRunner = new RoomRunner(relay);
                foreach (string s in roomRunner.Preload()) ;
				Room r1 = roomRunner.GetRoom("r1");

				PointTileNode start = r1.GetTile(new IntPoint(0, 5));
				PointTileNode goal = r1.GetTile(new IntPoint(9, 5));
				
				D.isNull(start);
				D.isNull(goal);
				
				PathSolver pathSolver = new PathSolver();
				Path path = pathSolver.FindPath(start, goal, roomRunner, true);
                
				Console.WriteLine("path resolved using " + path.pathSearchTestCount + " node tests");
                Console.WriteLine("path tile count " + path.nodes.Length);

				Assert.AreEqual(PathStatus.FOUND_GOAL, path.status);
			}
		}
Exemplo n.º 5
0
 public void Setup()
 {
     solver = new PathSolver<SampleNode>();
 }