// Sparsify the map by removing dead-end cells. private void Sparsify(VirtualMap map, VirtualMap vmapBelow) { // Compute the number of cells to remove as a percentage of the total number of cells in the map int noOfDeadEndCellsToRemove = (int)Math.Floor((decimal)sparsenessModifier / 100 * (map.ActualWidth * map.ActualHeight)); if (verbose) { Console.WriteLine("Sparsify: removing " + sparsenessModifier + "% i.e. " + noOfDeadEndCellsToRemove + " out of " + map.ActualWidth * map.ActualHeight + " cells"); } int noOfRemovedCells = 0; IEnumerable <CellLocation> deads; while (noOfRemovedCells < noOfDeadEndCellsToRemove) { // We sweep and remove all current dead ends deads = map.DeadEndCellLocations; int currentlyRemovedCells = 0; foreach (CellLocation location in deads) { if (vmapBelow != null && location == vmapBelow.end) { continue; // For multi-storey to work correctly, we do not remove the cell above the below's end } // Console.WriteLine("Dead at " + starting_location); // Console.WriteLine(map.CalculateDeadEndCorridorDirection(starting_location)); map.CreateWall(location, map.CalculateDeadEndCorridorDirection(location)); currentlyRemovedCells++; if (++noOfRemovedCells == noOfDeadEndCellsToRemove) { break; } } if (currentlyRemovedCells == 0) { // Console.WriteLine("We have no more dead ends!"); break; // No more dead endss } // Console.WriteLine("We removed a total of " + noOfRemovedCells + " cells"); } }