Example #1
0
        private void ShowNotesForSquare(ISudokuSquare square)
        {
            if (square.GetText().Trim().Length > 0)
            {
                return;
            }

            ShowNotesForSquareAt(square);
        }
Example #2
0
        bool CheckForConflicts(int r, int c, bool setHasConflictedProperty = true)
        {
            ISudokuSquare thisSquare = SudokuBoard.squares[r, c];
            string        text       = thisSquare.GetText();

            if (string.IsNullOrWhiteSpace(text))
            {
                return(false);
            }

            ISudokuSquare[] column = SudokuBoard.GetColumn(c);
            ISudokuSquare[] row    = SudokuBoard.GetRow(r);
            ISudokuSquare[] block  = SudokuBoard.GetBlock(r, c);

            bool isConflicted = false;

            for (int rowIndex = 0; rowIndex < 9; rowIndex++)
            {
                if (rowIndex != r && column[rowIndex].GetText() == text)
                {
                    if (setHasConflictedProperty)
                    {
                        thisSquare.HasConflict       = true;
                        column[rowIndex].HasConflict = true;
                    }
                    isConflicted = true;
                }
            }

            for (int colIndex = 0; colIndex < 9; colIndex++)
            {
                if (colIndex != c && row[colIndex].GetText() == text)
                {
                    if (setHasConflictedProperty)
                    {
                        thisSquare.HasConflict    = true;
                        row[colIndex].HasConflict = true;
                    }
                    isConflicted = true;
                }
            }

            for (int squareIndex = 0; squareIndex < 9; squareIndex++)
            {
                GetSquarePosition(block[squareIndex], out int blockRow, out int blockColumn);
                if (blockRow == r && blockColumn == c)
                {
                    continue;
                }

                if (block[squareIndex].GetText() == text)
                {
                    if (setHasConflictedProperty)
                    {
                        thisSquare.HasConflict         = true;
                        block[squareIndex].HasConflict = true;
                    }
                    isConflicted = true;
                }
            }

            return(isConflicted);
        }