Beispiel #1
0
        static void Main(string[] args)
        {
            try
            {
                SudokuBlockFinder       sudokuBlockFinder       = new SudokuBlockFinder();
                SudokuBoardStateManager sudokuBoardStateManager = new SudokuBoardStateManager();
                SudokuSolverEngine      sudokuSolverEngine      = new SudokuSolverEngine(sudokuBoardStateManager, sudokuBlockFinder);
                SudokuFileReader        sudokuFileReader        = new SudokuFileReader();
                SudokuDisplayer         sudokuDisplayer         = new SudokuDisplayer();

                Console.WriteLine("Enter the filename of the sudoku to solve");
                string filename    = Console.ReadLine();
                var    sudokuBoard = sudokuFileReader.ReadSudokuFile(filename);
                sudokuDisplayer.Display("Initial State", sudokuBoard);

                bool isSudokuSolved = sudokuSolverEngine.Solve(sudokuBoard);
                sudokuDisplayer.Display("Final State", sudokuBoard);

                //Final Message
                Console.WriteLine(isSudokuSolved
                    ? "Great! You solved this sudoku puzzle"
                    : "Sorry, my algorithms need to be improved for solve this one!"
                                  );
            } catch (Exception ex)
            {
                Console.WriteLine("{0}: {1}", "This Sudoku can not be solved. This is the error", ex.Message);
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            try
            {
                SudokuMapper            sudokuMapper            = new SudokuMapper();
                SudokuBoardStateManager sudokuBoardStateManager = new SudokuBoardStateManager();
                SudokuSolverEngine      sudokuSolverEngine      = new SudokuSolverEngine(sudokuBoardStateManager, sudokuMapper);
                SudokuFileReader        sudokuFileReader        = new SudokuFileReader();
                SudokuBoardDisplayer    sudokuBoardDisplayer    = new SudokuBoardDisplayer();

                Console.WriteLine("Enter the Filename for Sudoku puzzle");
                var fileName = Console.ReadLine();

                var sudokuBoard = sudokuFileReader.ReadSudokuFile(fileName);
                sudokuBoardDisplayer.Display("Initial State", sudokuBoard);

                bool isSudokuSolved = sudokuSolverEngine.Solve(sudokuBoard);
                sudokuBoardDisplayer.Display("Final State", sudokuBoard);

                Console.WriteLine(isSudokuSolved ?
                                  "Sudoku Puzzle Solved" : "Sudoku could not be solved");
            }
            catch (Exception ex)
            {
                Console.WriteLine("{0} {1}", "Sudoku puzzled cannot be solved because of an error", ex.Message);
            }
        }