Beispiel #1
0
        public bool TryAndSolveOnce(SudokuGrid inputGrid)
        {
            while (inputGrid.FindAllEmptySquares().Count != 0)
            {
                bool hasASquareBeenFilled = false;
                foreach (var emptySquare in inputGrid.FindAllEmptySquares())
                {
                    List <int> validOptionsForSquare = DetermineValidOptionsForSquare(emptySquare, inputGrid);

                    if (validOptionsForSquare.Count == 0)
                    {
                        return(false);
                    }
                    if (validOptionsForSquare.Count == 1)
                    {
                        inputGrid.FillInSquare(emptySquare, validOptionsForSquare[0]);
                        hasASquareBeenFilled = true;
                    }
                }

                if (!hasASquareBeenFilled)
                {
                    return(true);
                }
            }

            return(true);
        }
Beispiel #2
0
        public bool TryAndSolveOnce(SudokuGrid inputGrid)
        {
            while (inputGrid.FindAllEmptySquares().Count != 0)
            {
                bool hasASquareBeenFilled = false;
                foreach (var emptySquare in inputGrid.FindAllEmptySquares())
                {
                    List<int> validOptionsForSquare = DetermineValidOptionsForSquare(emptySquare, inputGrid);

                    if (validOptionsForSquare.Count == 0)
                    {
                        return false;
                    }
                    if (validOptionsForSquare.Count == 1)
                    {
                        inputGrid.FillInSquare(emptySquare, validOptionsForSquare[0]);
                        hasASquareBeenFilled = true;
                    }
                }

                if (!hasASquareBeenFilled)
                {
                    return true;
                }
            }

            return true;
        }