private int EdgeCoverage(int x, int y, bool[,] continuousVisited, bool[,] edgesVisited, Color[,] board) { continuousVisited.SetAt(x, y, true); Color thisColor = board.GetAt(x, y); int result = 0; if (board.CanGetLeft(x) && !continuousVisited.GetLeftOf(x, y)) { if (thisColor == board.GetLeftOf(x, y)) { result += EdgeCoverage(x - 1, y, continuousVisited, edgesVisited, board); } else if (!edgesVisited.GetLeftOf(x, y)) { edgesVisited.SetLeftOf(x, y, true); result++; } } if (board.CanGetAbove(y) && !continuousVisited.GetAboveOf(x, y)) { if (thisColor == board.GetAboveOf(x, y)) { result += EdgeCoverage(x, y - 1, continuousVisited, edgesVisited, board); } else if (!edgesVisited.GetAboveOf(x, y)) { edgesVisited.SetAboveOf(x, y, true); result++; } } if (board.CanGetRight(x) && !continuousVisited.GetRightOf(x, y)) { if (thisColor == board.GetRightOf(x, y)) { result += EdgeCoverage(x + 1, y, continuousVisited, edgesVisited, board); } else if (!edgesVisited.GetRightOf(x, y)) { edgesVisited.SetRightOf(x, y, true); result++; } } if (board.CanGetBelow(y) && !continuousVisited.GetBelowOf(x, y)) { if (thisColor == board.GetBelowOf(x, y)) { result += EdgeCoverage(x, y + 1, continuousVisited, edgesVisited, board); } else if (!edgesVisited.GetBelowOf(x, y)) { edgesVisited.SetBelowOf(x, y, true); result++; } } return(result); }