public static List <HashSet <Vec2i> > Islands( this PM_Maze maze, Random rand) { List <HashSet <Vec2i> > islands = new List <HashSet <Vec2i> >(); HashSet <Vec2i> allCells = maze.CellsPositions_All_Set(); while (allCells.Count > 0) { Vec2i randomCell = allCells.Random_Item(rand); HashSet <Vec2i> island = maze.BFS_ReachableCells_Set(randomCell, true); islands.Add(island); allCells.ExceptWith(island); //allCells.RemoveWhere(x => island.Contains(x)); } return(islands); }