Sudoku.CheckCorrectCell.checkCorrectCell9x9 C# (CSharp) Method

checkCorrectCell9x9() public method

public checkCorrectCell9x9 ( int x, int y ) : bool
x int
y int
return bool
        public bool checkCorrectCell9x9(int x, int y)
        {
            for (int i = 0; i < 9; i++)
            {
                if (table[x, y] == table[x, i] && y != i)
                {
                    return true;
                }
            }

            for (int j = 0; j < 9; j++)
            {
                if (table[x, y] == table[j, y] && x != j)
                {
                    return true;
                }
            }

            int[] rowCol = checkSmallPositionPart(x, y);
            int row = rowCol[0];
            int col = rowCol[1];

            for (int i = row; i < row + 3; i++)
            {
                for (int j = col; j < col + 3; j++)
                {
                    if (table[x, y] == table[i, j] && x != i && y != j)
                    {
                        return true;
                    }
                }
            }

            return false;
        }

Usage Example

コード例 #1
0
ファイル: Form1.cs プロジェクト: triplesic/SudokuNewProject
 private void Box6_TextChanged(object sender, EventArgs e)
 {
     int[,] arr = mapTableToArray(); CCC = new CheckCorrectCell(arr);
     if (CCC.checkCorrectCell9x9(0, 5) &&
         Box6.Text != "")
     {
         Box6.BackColor = Color.Red;
     }
     else
         Box6.BackColor = Color.White;
     congratulations9x9();
 }