Sudoku.Board.Solve C# (CSharp) Method

Solve() public method

public Solve ( ) : bool
return bool
        public bool Solve()
        {
            if (this.IsSolved) return true;
            if (this.HasDeadSquares)
                return false;

            var orderedMoves = this.GenerateMoves().OrderBy(move => move.Score);

            foreach (Move move in orderedMoves)
            {
                this.MakeMove(move);
                if (this.Solve()) return true;
                this.UnmakeMove(move);
            }

            return false;
        }

Usage Example

Example #1
0
        static void Main(string[] args)
        {
            var b1     = Board.ReadInString("000010000007905400000804000001000200470030096000090000016050940004321600308000102");
            var board1 = new Board(b1);

            board1.PrintOut();
            Console.Out.WriteLine("going to solve now");
            Console.Out.WriteLine("\n\n");
            board1.Solve();
            board1.IsValid();
            //board1.Assign();
            Console.Read();
        }
All Usage Examples Of Sudoku.Board::Solve