public static Level TrimWalls(Level level) { // First make a copy. Level newLevel = new Level(level); // Delete walls that don't contact the interior. foreach (Coordinate2D coord in newLevel.Coordinates) { if (!level.IsWall(coord)) { continue; } bool foundInterior = false; foreach (Coordinate2D neighbor in coord.EightNeighbors) { if (level.IsInside(neighbor)) { foundInterior = true; break; } } if (!foundInterior) { newLevel[coord] = Cell.Empty; } } return newLevel; }