Пример #1
0
        public void Move(MapRenderer mapRenderer, int goal_minitile_x, int goal_minitile_y)
        {
            if (false /*flying unit*/)
            {
                // easier case, take the direct route
            }
            else
            {
                // Console.WriteLine ("FindPath from {0},{1} -> {2},{3}",
                //         x >> 2, y >> 2,
                //         goal_minitile_x, goal_minitile_y);

                navigateDestination = new MapPoint(goal_minitile_x, goal_minitile_y);

                AStarSolver astar = new AStarSolver(mapRenderer);

                navigatePath = astar.FindPath(new MapPoint(x >> 2, y >> 2),
                                              navigateDestination);

                sprite.Debug = true;

                if (navigatePath != null)
                {
                    NavigateAlongPath();
                }
            }
        }
Пример #2
0
        public static void Main(string[] args)
        {
            Map m = new Map(50, 50);

            for (int i = 0; i < 25; i++)
            {
                m.AddWall(new MapPoint(15, i));
            }

            AStarSolver solver = new AStarSolver(m);

            List <MapPoint> path = solver.FindPath(new MapPoint(10, 10), new MapPoint(20, 10));

            Dictionary <MapPoint, bool> path_points = new Dictionary <MapPoint, bool>();

            foreach (var p in path)
            {
                path_points.Add(p, true);
            }

            for (int y = 0; y < 50; y++)
            {
                for (int x = 0; x < 50; x++)
                {
                    MapPoint point = new MapPoint(x, y);
                    if (point == new MapPoint(20, 10))
                    {
                        Console.Write("X");
                    }
                    else if (path_points.ContainsKey(point))
                    {
                        Console.Write("x");
                    }
                    else if (!m.Navigable(point))
                    {
                        Console.Write("O");
                    }
                    else if (solver.closedset.ContainsKey(point))
                    {
                        Console.Write(".");
                    }
                    else
                    {
                        Console.Write(" ");
                    }
                }
                Console.WriteLine();
            }

            // Console.WriteLine ("Path = {{");
            // foreach (MapPoint point in path) {
            //  Console.WriteLine ("   {0}, {1}", point.X, point.Y);
            // }
            // Console.WriteLine ("}");
        }
Пример #3
0
		public static void Main (string[] args) {
			Map m = new Map (50, 50);

			for (int i = 0; i < 25; i ++)
				m.AddWall (new MapPoint (15, i));

			AStarSolver solver = new AStarSolver (m);

			List<MapPoint> path = solver.FindPath (new MapPoint (10, 10), new MapPoint (20, 10));

			Dictionary<MapPoint,bool> path_points = new Dictionary<MapPoint,bool>();
			foreach (var p in path)
				path_points.Add (p, true);

			for (int y = 0; y < 50; y ++) {
				for (int x = 0; x < 50; x ++) {
					MapPoint point = new MapPoint (x,y);
					if (point == new MapPoint (20,10))
						Console.Write ("X");
					else if (path_points.ContainsKey (point))
						Console.Write ("x");
					else if (!m.Navigable (point))
						Console.Write ("O");
					else if (solver.closedset.ContainsKey (point))
						Console.Write (".");
					else
						Console.Write (" ");
				}
				Console.WriteLine();
			}

			// Console.WriteLine ("Path = {{");
			// foreach (MapPoint point in path) {
			// 	Console.WriteLine ("   {0}, {1}", point.X, point.Y);
			// }
			// Console.WriteLine ("}");
		}
Пример #4
0
		public void Move (MapRenderer mapRenderer, int goal_minitile_x, int goal_minitile_y)
		{
			if (false /*flying unit*/) {
				// easier case, take the direct route
			}
			else {
				// Console.WriteLine ("FindPath from {0},{1} -> {2},{3}",
				// 		   x >> 2, y >> 2,
				// 		   goal_minitile_x, goal_minitile_y);

				navigateDestination = new MapPoint (goal_minitile_x, goal_minitile_y);

				AStarSolver astar = new AStarSolver (mapRenderer);

				navigatePath = astar.FindPath (new MapPoint (x >> 2, y >> 2),
							       navigateDestination);

				sprite.Debug = true;

				if (navigatePath != null)
					NavigateAlongPath ();
			}
		}