GetNodeIdFromPos() public method

public GetNodeIdFromPos ( int x, int y ) : int
x int
y int
return int
示例#1
0
        private static List <IPathNode> RegularSearch(ConcreteMap concreteMap, Position startPosition, Position endPosition)
        {
            var tilingGraph = concreteMap.Graph;
            Func <int, int, ConcreteNode> getNode =
                (top, left) => tilingGraph.GetNode(concreteMap.GetNodeIdFromPos(top, left));

            // Regular pathfinding
            var searcher = new AStar <ConcreteNode>(concreteMap, getNode(startPosition.X, startPosition.Y).NodeId, getNode(endPosition.X, endPosition.Y).NodeId);
            var path     = searcher.FindPath();
            var path2    = path.PathNodes;

            return(new List <IPathNode>(path2.Select(p => (IPathNode) new ConcretePathNode(p))));
        }
        // Create a new concreteMap as a copy of another concreteMap (just copying obstacles)
        public ConcreteMap Slice(int horizOrigin, int vertOrigin, int width, int height, IPassability passability)
        {
            var slicedConcreteMap = new ConcreteMap(this.TileType, width, height, passability);
			
			// so we now put the obstacles in place
			for (var x = 0; x < width; x++)
				for (var y = 0; y < height; y++)
				{
					// get the local node
					var localNodeInfo = slicedConcreteMap.Graph.GetNode(slicedConcreteMap.GetNodeIdFromPos(x, y)).Info;
					// get the initial concreteMap node
					var nodeInfo = this.Graph.GetNode(this.GetNodeIdFromPos(horizOrigin + x, vertOrigin + y)).Info;
					// set obstacle for the local node
					localNodeInfo.IsObstacle = nodeInfo.IsObstacle;
					localNodeInfo.Cost = nodeInfo.Cost;
				}

            return slicedConcreteMap;
		}
示例#3
0
        private static void PrintFormatted(List <char> chars, ConcreteMap concreteMap, HierarchicalMap hierarchicalGraph, int clusterSize, List <Position> path)
        {
            for (var y = 0; y < concreteMap.Height; y++)
            {
                if (y % clusterSize == 0)
                {
                    Console.WriteLine("---------------------------------------------------------");
                }
                for (var x = 0; x < concreteMap.Width; x++)
                {
                    Console.ForegroundColor = ConsoleColor.White;
                    if (x % clusterSize == 0)
                    {
                        Console.Write('|');
                    }

                    var nodeId     = concreteMap.GetNodeIdFromPos(x, y);
                    var hasAbsNode = hierarchicalGraph.AbstractGraph.Nodes.SingleOrDefault(n => n.Info.ConcreteNodeId == nodeId);

                    if (hasAbsNode != null)
                    {
                        switch (hasAbsNode.Info.Level)
                        {
                        case 1: Console.ForegroundColor = ConsoleColor.Red;
                            break;

                        case 2: Console.ForegroundColor = ConsoleColor.DarkGreen;
                            break;
                        }
                    }

                    Console.Write(path.Any(node => node.X == x && node.Y == y) ? 'X' : chars[nodeId.IdValue]);
                }

                Console.WriteLine();
            }
        }
示例#4
0
        private static void PrintFormatted(List<char> chars, ConcreteMap concreteMap, HierarchicalMap hierarchicalGraph, int clusterSize, List<Position> path)
        {
            for (var y = 0; y < concreteMap.Height; ++y)
            {
                if (y % clusterSize == 0) Console.WriteLine("---------------------------------------------------------");
                for (var x = 0; x < concreteMap.Width; ++x)
                {
                    Console.ForegroundColor = ConsoleColor.White;
                    if (x % clusterSize == 0) Console.Write('|');

                    var nodeId = concreteMap.GetNodeIdFromPos(x, y);
                    var hasAbsNode = hierarchicalGraph.AbstractGraph.Nodes.FirstOrDefault(n => n.Info.CenterId == nodeId);
                    
                    if (hasAbsNode != null)
                        switch (hasAbsNode.Info.Level)
                        {
                            case 1: Console.ForegroundColor = ConsoleColor.Red;
                                break;
                            case 2: Console.ForegroundColor = ConsoleColor.DarkGreen;
                                break;
                        }
                        
                    Console.Write(path.Any(n => n.X == x && n.Y == y) ? 'X' : chars[nodeId]);
                }

                Console.WriteLine();
            }
        }
示例#5
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();
	    }