private static void FlipSimilarCluster(Floodling floodling, bool[,] map, bool[,] visited) //Forgot what this does lmao { Stack <Point> stack = new Stack <Point>(); stack.Push(new Point(floodling.Source.X, floodling.Source.Y)); Point currentCell; while (stack.Count > 0) { currentCell = stack.Pop(); if (currentCell.X < 0 || currentCell.X > map.GetLength(0) - 1 || currentCell.Y < 0 || currentCell.Y > map.GetLength(1) - 1) { continue; } if (map[currentCell.X, currentCell.Y] == floodling.Value && !visited[currentCell.X, currentCell.Y]) { map[currentCell.X, currentCell.Y] = !floodling.Value; visited[currentCell.X, currentCell.Y] = true; stack.Push(new Point(currentCell.X - 1, currentCell.Y)); stack.Push(new Point(currentCell.X + 1, currentCell.Y)); stack.Push(new Point(currentCell.X, currentCell.Y - 1)); stack.Push(new Point(currentCell.X, currentCell.Y + 1)); } } }
private static void RunFloodling(int x, int y, bool[,] map, bool[,] visited, List <Floodling> floodlings) { Floodling floodling = new Floodling(map[x, y], x, y); Stack <Point> stack = new Stack <Point>(); stack.Push(new Point(x, y)); Point currentCell; while (stack.Count > 0) { currentCell = stack.Pop(); if (currentCell.X < 0 || currentCell.X > map.GetLength(0) - 1 || currentCell.Y < 0 || currentCell.Y > map.GetLength(1) - 1) { continue; } if (map[currentCell.X, currentCell.Y] == floodling.Value && !visited[currentCell.X, currentCell.Y]) { floodling.Count++; visited[currentCell.X, currentCell.Y] = true; stack.Push(new Point(currentCell.X - 1, currentCell.Y)); stack.Push(new Point(currentCell.X + 1, currentCell.Y)); stack.Push(new Point(currentCell.X, currentCell.Y - 1)); stack.Push(new Point(currentCell.X, currentCell.Y + 1)); } } floodlings.Add(floodling); }