Ejemplo n.º 1
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("Please enter the filename containing the sudoku puzzle:");
                var filename = Console.ReadLine();

                var sudokuBoard = sudokuFileReader.ReadFile(filename);
                sudokuBoardDisplayer.Display("Initial State", sudokuBoard);

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

                Console.WriteLine(isSudokuSolved ? "You have successfully solved this sudoku puzzle!" : "unfortunately, current algorithm(s) were not enough to solve the current sudoku puzzle!");
            }

            catch (Exception ex)
            {
                // In real world we would want to log this message
                Console.WriteLine("{0} : {1}", "Sudoku Puzzle cannot be solved because there was an error:", ex.Message);
            }
        }
Ejemplo n.º 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();

                WriteLine("Please Enter the filename containing Sudoku Puzzle:\t");
                var filename = ReadLine();

                var sudokuBoard = sudokuFileReader.ReadFile(filename);
                sudokuBoardDisplayer.Display("initial State", sudokuBoard);

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

                WriteLine(isSudokuSolved
                    ? "You have successfully solved the puzzle"
                    : "Your strategies are not intelegent enough to solve the sukodu puzzle ....");
            }
            catch (Exception ex)
            {
                WriteLine($"Sudoku puzzle cannot be solved as there is the problem \n{ex.Message}");
            }
        }
Ejemplo n.º 3
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("Please enter the filename with Sudoku Puzzle:");
                var filename = Console.ReadLine();

                var sudokuBoard = sudokuFileReader.ReadFile(filename);
                sudokuBoardDisplayer.Display("Initial State", sudokuBoard);

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

                Console.WriteLine(isSudokuSolved ? "You have succesfully this Sudoku Puzzle" : "Unable to solve that Sudoku now.");
            }
            catch (Exception ex)
            {
                Console.WriteLine("{0} : {1}", "Sudoku puzzle cannot be solved because of error", ex.Message);
            }
        }
Ejemplo n.º 4
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);
            }
        }
Ejemplo n.º 5
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("Please enter the filename containing the sudoku puzzle: ");
                var filename = Console.ReadLine();

                var sudokuBoard = sudokuFileReader.ReadFile(filename);
                sudokuBoardDisplayer.Display("Initial State", sudokuBoard);

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

                Console.WriteLine(isSudokuSolved
                    ? "You have successfully solved this sudoku puzzle!"
                    : "Unfortunately, the current algorithms weren't enough to solve the puzzle.");

                Console.WriteLine("Press any key to continue...");
                Console.ReadKey();
            }
            catch (Exception ex)
            {
                Console.WriteLine("{0} : {1}", "Sudoku puzzle cannot be solved becasue there was an error: ", ex.Message);
            }
        }
Ejemplo n.º 6
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);
            }
        }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            try
            {
                SudokuMapper       sudokuMapper       = new SudokuMapper();
                BoardStateManager  boardStateManager  = new BoardStateManager();
                SudokuSolverEngine sudokuSolverEngine = new SudokuSolverEngine(boardStateManager, sudokuMapper);
                SudokuFileReader   sudokuFileReader   = new SudokuFileReader();
                BoardDisplayer     boardDisplayer     = new BoardDisplayer();

                Console.WriteLine("Please enter the FileName that contains the sudoku puzzle");
                var fileName = Console.ReadLine();

                var sudokuBoard = sudokuFileReader.ReadFile(fileName);
                boardDisplayer.Display("Initial State", sudokuBoard);

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

                Console.WriteLine(isSudokuSolved ? "Puzzle was solved" : "Falied to solve the puzzle");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Something went wrong, try again" + ex.Message);
            }
        }
Ejemplo n.º 8
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("Please enter the filename containing the Sudoku puzzle:");
            var fileName = Console.ReadLine();

            var sudokuBoard = sudokuFileReader.ReadFile(fileName);

            sudokuBoardDisplayer.Display("Initial state", sudokuBoard);

            bool isSudokuSolved = sudokuSolverEngine.Solve(sudokuBoard);

            sudokuBoardDisplayer.Display("Final state", sudokuBoard);

            Console.WriteLine(isSudokuSolved
                    ? "You have successfully solved this Sudoku puzzle!"
                    : "Unfortunately, the current algorithm(s) were not enough to solve the Sudoku puzzle...");
            //}
            //catch(Exception ex)
            //{
            //    Console.WriteLine($"Sudoku puzzle cannot be solved because there was an error: {ex.Message}");
            //}
        }
        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("Please enter the file name containing the sudoku puzzle");
                var fileName = Console.ReadLine();

                var sudokuBoard = sudokuFileReader.ReadFile(fileName);
                sudokuBoardDisplayer.Display("Initial state", sudokuBoard);

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

                Console.WriteLine(isSudokuSolved ? "You have successfully solved this Sudoku Puzzle" : "Current algorithm(s) were not enough to solve the current Sudoku Puzzle");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Sudoku puzzle cannot be solved because there was an arror " + ex.Message);
            }
        }
Ejemplo n.º 10
0
        public static void Main()
        {
            try {
                var sudokuMapper      = new SudokuMapper();
                var boardStateManager = new BoardStateManager();
                var solverEngine      = new SudokuSolverEngine(boardStateManager, sudokuMapper);
                var boardDisplayer    = new BoardDisplayer();

                Console.WriteLine("Please enter the filename containing the sudoku puzzle");
                var fileName    = Console.ReadLine();
                var sudokuBoard = SudokuFileReader.ReadBoardFromFile(fileName);
                boardDisplayer.Display("Initial State", sudokuBoard);
                bool isSolved = solverEngine.Solve(sudokuBoard);
                boardDisplayer.Display("Final State", sudokuBoard);
                Console.WriteLine(isSolved ? "Sudoku puzzle was solved successfully" : "Current algorithms can " +
                                  "not solve this puzzle");
            }
            catch (Exception e) {
                Console.WriteLine("An error occured trying to solve sudoku puzzle : {0}", e.Message);
                Console.WriteLine(e.StackTrace);
            }
        }
Ejemplo n.º 11
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("Please enter the filename containing the Sudoku Puzzle:");
                var userInput = Console.ReadLine();

                var filename = userInput + ".txt";



                var sudokuBoard = sudokuFileReader.ReadFile(filename);
                sudokuBoardDisplayer.Display("Inital State", sudokuBoard);

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

                Console.WriteLine(isSudokuSolved ?
                                  "You have successfully solved this Sudoku Puzzle!"
                    : "Unfortunatley, current algorithm(s) were not enough to solve the current Sudoku Puzzle!");

                Console.WriteLine("\n\n\n Press any key to exit");
                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine("{0} {1}", "Sudoku puzzle cannot be solved because there was an error:", ex.Message);

                Console.WriteLine("\n\n\n Press any key to exit");
                Console.ReadLine();
            }
        }
        static void Main(string[] args)
        {
            try
            {
                var mapper            = new SudokuMapper();
                var boardStateManager = new SudokuBoardStateManager();
                var solverEngine      = new SudokuSolverEngine(mapper, boardStateManager);
                var fileReader        = new SudokuFileReader();
                var displayer         = new SudokuBoardDisplayer();
                Console.WriteLine("Please enter the filename containing the sudoku puzzle");
                var fileName = Console.ReadLine();

                var sudokuBoard = fileReader.ReadFile(fileName);
                displayer.Display("Initial State", sudokuBoard);
                var isSolved = solverEngine.Solve(sudokuBoard);
                displayer.Display("Final State", sudokuBoard);

                Console.WriteLine(isSolved ? "You have successfully solved the sudoku puzzle":"Unfortunately puzzle not solved");
            }
            catch (Exception e)
            {
                Console.WriteLine($"Sudoku puzzle cannot be solved because there was an error: {e.Message}");
            }
        }