Пример #1
0
		public void a()
		{
			var astar = new AStar();
			
			// create a map

			//IMap map = new TilingTests(TileType.OCTILE, 10, 10, );
			//astar.FindPath()
		}
        public List<int> PerformSearch(HierarchicalMap map, int startNodeId, int targetNodeId, int level, bool mainSearch)
        {
            var search = new AStar();
            map.SetCurrentLevel(level);
            var nodeInfo = map.AbstractGraph.GetNodeInfo(startNodeId);
            if (mainSearch)
                map.SetCurrentCluster(nodeInfo.Position, map.MaxLevel + 1);
            else
                map.SetCurrentCluster(nodeInfo.Position, level + 1);

            // TODO: This could be perfectly replaced by cached paths in the clusters!
            var path = search.FindPath(map, startNodeId, targetNodeId);
            if (path.PathCost == -1)
            {
                // No path found
                return new List<int>();
            }

            var result = path.PathNodes;
            result.Reverse();
            return result;
        }
		/// <summary>
		/// Adds an edge between two abstract nodes for a given level
		/// </summary>
		private static void AddEdgesBetweenAbstractNodes(HierarchicalMap map, int absNodeId1, int absNodeId2, int level)
		{
			if (absNodeId1 == absNodeId2 || !IsValidAbstractNode(map, absNodeId2, level))
				return;

			var search = new AStar();
			var path = search.FindPath(map, absNodeId1, absNodeId2);
			if (path.PathCost >= 0)
			{
				map.AddEdge(absNodeId1, absNodeId2, path.PathCost, level, false);
				map.AddEdge(absNodeId2, absNodeId1, path.PathCost, level, false);
			}
		}
Пример #4
0
	    private static List<Position> RegularSearch(ConcreteMap concreteMap)
	    {
			var tilingGraph = concreteMap.Graph;
			Func<int, int, Graph<TilingNodeInfo, TilingEdgeInfo>.Node> getNode =
				(top, left) => tilingGraph.GetNode(concreteMap.GetNodeIdFromPos(top, left));

			// Regular pathfinding
			var searcher = new AStar();
			var path = searcher.FindPath(concreteMap, getNode(StartPosition.X, StartPosition.Y).NodeId, getNode(EndPosition.X, EndPosition.Y).NodeId);
	        var path2 = path.PathNodes;
		    return path2.Select(n => concreteMap.Graph.GetNodeInfo(n).Position).ToList();
	    }
Пример #5
0
        private void ComputePathBetweenEntrances(EntrancePoint e1, EntrancePoint e2)
        {
            var start = GetEntrancePositionIndex(e1);
            var target = GetEntrancePositionIndex(e2);
            var startIdx = e1.EntranceLocalIdx;
            var targetIdx = e2.EntranceLocalIdx;
	        var tuple = Tuple.Create(startIdx, targetIdx);
			var invtuple = Tuple.Create(targetIdx, startIdx);

			// If a path already existed, or both are the same node, just return
			if (this.DistanceCalculated.ContainsKey(tuple) || startIdx == targetIdx)
                return;

            var search = new AStar();
            var path = search.FindPath(SubConcreteMap, start, target);

            // TODO: Store the path as well, not only the cost. This will make everything faster!
	        if (path.PathCost != -1)
	        {
				// Yeah, we are supposing reaching A - B is the same like reaching B - A. Which
				// depending on the game this is NOT necessarily true (e.g climbing, downstepping a mountain)
		        Distances[tuple] = Distances[invtuple] = path.PathCost;
		        CachedPaths[tuple] = CachedPaths[invtuple] = path.PathNodes;
	        }

            this.DistanceCalculated[tuple] = this.DistanceCalculated[invtuple] = true;
        }
Пример #6
0
 public List<int> ComputePath(int start, int target)
 {
     var search = new AStar();
     var path = search.FindPath(SubConcreteMap, target, start);
     return path.PathNodes;
 }
Пример #7
0
 private List<int> GenerateIntermediateNodes(int nodeid1, int nodeid2)
 {
     var search = new AStar();
     var path = search.FindPath(concreteMap, nodeid1, nodeid2);
     return path.PathNodes;
 }