Пример #1
0
 public void InitializeExploration()
 {
     Exploration = new Exploration(mapDataForExploration, totalExploreSum);
 }
Пример #2
0
        public SubMap(byte[,] processedFullSizeMapDataForPathFinding, byte[,] processedFullSizeMapDataForExploration, int[,] islandProcessedMapDataForPathFinding, int islandId)
        {
            var startTime = DateTime.Now;

            this.IslandId = islandId;
            this.mapDataForExploration = processedFullSizeMapDataForExploration.Clone() as byte[, ];

            EraseNonIslandData(this.mapDataForExploration, islandProcessedMapDataForPathFinding, islandId);

            //var nodeA = new Node(new Position(1, 1));
            //var nodeB = new Node(new Position(2, 2));
            //nodeA.Connect(nodeB,2)

            int reducedWidth        = processedFullSizeMapDataForPathFinding.GetLength(0) / PathfindingConsts.myPathfindingGridSize;
            int reducedHeight       = processedFullSizeMapDataForPathFinding.GetLength(1) / PathfindingConsts.myPathfindingGridSize;
            var gridSize            = new GridSize(columns: reducedWidth, rows: reducedHeight);
            var cellSize            = new Size(Distance.FromMeters(PathfindingConsts.myPathfindingGridSize), Distance.FromMeters(PathfindingConsts.myPathfindingGridSize));
            var traversalVelocity   = Velocity.FromKilometersPerHour(100);
            var startTimeGridCreate = DateTime.Now;

            Grid = Grid.CreateGridWithLateralAndDiagonalConnections(gridSize, cellSize, traversalVelocity);
            Console.WriteLine($"Creating grid took: {DateTime.Now.Subtract(startTimeGridCreate).TotalMilliseconds} milliseconds");

            //Parallel.For(0, reducedWidth, x =>
            // {

            var startTimeGridPrep = DateTime.Now;

            for (int x = 0; x < reducedWidth; x++)
            {
                for (int y = 0; y < reducedHeight; y++)
                {
                    int xAdjusted = x * PathfindingConsts.myPathfindingGridSize;
                    int yAdjusted = y * PathfindingConsts.myPathfindingGridSize;

                    if (processedFullSizeMapDataForPathFinding[xAdjusted, yAdjusted] == 0 || islandProcessedMapDataForPathFinding[xAdjusted, yAdjusted] != islandId)
                    {
                        // Grid.RemoveDiagonalConnectionsIntersectingWithNode(new GridPosition(x, y));
                        Grid.DisconnectNode(new GridPosition(x, y));
                    }
                    //if (processedFullSizeMapDataForPathFinding[xAdjusted, yAdjusted] != 0 && islandProcessedMapDataForPathFinding[xAdjusted, yAdjusted] != islandId)
                    //{
                    //    Grid.RemoveDiagonalConnectionsIntersectingWithNode(new GridPosition(x, y));
                    //    Grid.DisconnectNode(new GridPosition(x, y));
                    //}
                }
            }
            Console.WriteLine($"Prepping grid took: {DateTime.Now.Subtract(startTimeGridPrep).TotalMilliseconds} milliseconds");

            //});

            //for (int x = 0; x < reducedWidth; x++)
            //{
            //    for (int y = 0; y < reducedHeight; y++)
            //    {
            //        int xAdjusted = x * PathfindingConsts.myPathfindingGridSize;
            //        int yAdjusted = y * PathfindingConsts.myPathfindingGridSize;

            //        if (processedFullSizeMapDataForPathFinding[xAdjusted, yAdjusted] == 0)
            //        {
            //            // Grid.RemoveDiagonalConnectionsIntersectingWithNode(new GridPosition(x, y));
            //            Grid.DisconnectNode(new GridPosition(x, y));
            //        }
            //        if (processedFullSizeMapDataForPathFinding[xAdjusted, yAdjusted] != 0 && islandProcessedMapDataForPathFinding[xAdjusted, yAdjusted] != islandId)
            //        {
            //            //Grid.RemoveDiagonalConnectionsIntersectingWithNode(new GridPosition(x, y));
            //            Grid.DisconnectNode(new GridPosition(x, y));
            //        }
            //    }
            //}
            var startTimeExplorationPrep = DateTime.Now;

            Exploration = new Exploration(mapDataForExploration);
            Console.WriteLine($"Prepping exploration took: {DateTime.Now.Subtract(startTimeExplorationPrep).TotalMilliseconds} milliseconds");


            Console.WriteLine($"Creating submap took: {DateTime.Now.Subtract(startTime).TotalMilliseconds} milliseconds");
        }