Esempio n. 1
0
		public static void Main(string[] args)
        {
            // Prepare the abstract graph beforehand
			IPassability passability = new FakePassability(Width, Height);
            var tiling = TilingFactory.CreateTiling(Width, Height, passability);
            var wizard = new AbstractMapFactory();
			wizard.CreateHierarchicalMap(tiling, ClusterSize, MaxLevel, EntranceStyle.END_ENTRANCE);
			var absTiling = wizard.HierarchicalMap;
			var sw = Stopwatch.StartNew();
            var path1 = RegularSearch(tiling);
	        var elapsed = sw.ElapsedMilliseconds;
			

			Console.WriteLine("Regular search: " + elapsed + " ms");
			Console.WriteLine($"{path1.Count} path nodes");
			PrintFormatted(tiling, absTiling, ClusterSize, path1);

			Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();
			
			sw = Stopwatch.StartNew();
            var path2 = HierarchicalSearch(absTiling, MaxLevel, tiling);
	        elapsed = sw.ElapsedMilliseconds;
			Console.WriteLine("Hierachical search: " + elapsed + " ms");
			Console.WriteLine($"{path2.Count} path nodes");
			PrintFormatted(tiling, absTiling, ClusterSize, path2);

            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine("Press any key to quit...");
            Console.ReadKey();
        }
Esempio n. 2
0
	    private static List<Position> HierarchicalSearch(HierarchicalMap hierarchicalMap, int maxLevel, ConcreteMap concreteMap)
	    {
			// Hierarchical pathfinding
			var factory = new AbstractMapFactory();
			var startAbsNode = factory.InsertAbstractNode(hierarchicalMap, StartPosition, 0);
	        var targetAbsNode = factory.InsertAbstractNode(hierarchicalMap, EndPosition, 1);
	        var maxPathsToRefine = int.MaxValue;
            var hierarchicalSearch = new HierarchicalSearch();
            var abstractPath = hierarchicalSearch.DoHierarchicalSearch(hierarchicalMap, startAbsNode, targetAbsNode, maxLevel, maxPathsToRefine);
			var path = hierarchicalSearch.AbstractPathToLowLevelPath(hierarchicalMap, abstractPath, hierarchicalMap.Width, maxPathsToRefine);
			factory.RemoveAbstractNode(hierarchicalMap, targetAbsNode, 1);
			factory.RemoveAbstractNode(hierarchicalMap, startAbsNode, 0);
            //var smoother = new SmoothWizard(concreteMap, path);
            //path = smoother.SmoothPath();
		    return path.Select(p => concreteMap.Graph.GetNodeInfo(p.Id).Position).ToList();
			//return path.Select(n => n.Level == 0 ? concreteMap.Graph.GetNodeInfo(n.Id).Position : hierarchicalMap.AbstractGraph.GetNodeInfo(n.Id).Position).ToList();
        }