Exemplo n.º 1
0
        static void Main(string[] args)
        {
            try
            {
                var sudokuMapper   = new SudokuMapper();
                var sbStateManager = new StateManager();
                var sbSolverEngine = new SolverEngine(sbStateManager, sudokuMapper);
                var sbFileReader   = new SudokuFileReader();
                var sbDisplayer    = new SudokuBoardDisplayer();

                Console.Write("Entrez le nom du fichier .txt contenant le puzzle Sudoku : ");
                var filename = Console.ReadLine();

                var sudokuBoard = sbFileReader.ReadFile(filename);
                sbDisplayer.Display("Puzzle Initial", sudokuBoard);

                bool isSolved = sbSolverEngine.Solve(sudokuBoard);
                sbDisplayer.Display("Puzzle résolu", sudokuBoard);

                Console.WriteLine(isSolved ? "Great !!! Resolve Successful" : "Un nain le mouvement est mal hard");
            }
            catch (Exception e)
            {
                Console.WriteLine("{0} : {1}", "Erreur Bro : ", e.Message);
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            try
            {
                Mapper            mapper            = new Mapper();
                BoardStateManager boardStateManager = new BoardStateManager();
                SolverEngine      solverEngine      = new SolverEngine(boardStateManager, mapper);
                FileReader        fileReader        = new FileReader();
                BoardDisplayer    boardDisplayer    = new BoardDisplayer();

                Console.Write("Enter the filename containing the sudoku puzzle: ");
                var filename = Console.ReadLine();

                var sudokuBoard = fileReader.ReadFile(filename);
                boardDisplayer.Display("Initial State", sudokuBoard);
                bool isSudokuSolved = solverEngine.Solve(sudokuBoard);
                boardDisplayer.Display("Final State", sudokuBoard);

                Console.WriteLine(isSudokuSolved
                    ? "Successfully solved puzzle!"
                    : "Unfortunately, our algorithms couldn't solve the sudoku puzzle");
            }
            catch (Exception ex)
            {
                Console.WriteLine("{0} : {1}", "Sudoku puzzle cannot be solved because there was an error: ", ex.Message);
            }
        }
Exemplo n.º 3
0
        public void Solve(int[,] sudokuBoard)
        {
            try
            {
                // Init mapper
                Mapper mapper = new Mapper();
                // Init boardStateManager
                BoardStateManager boardStateManager = new BoardStateManager();
                // Init solver Engine
                SolverEngine solverEngine = new SolverEngine(boardStateManager, mapper);
                // Init sudokuBoard
                int[,] sudokuBord = sudokuBoard;

                // Check if the sudoku is solved
                IsSolved = solverEngine.Solve(sudokuBord);
            }
            // Throw an error
            catch (Exception ex)
            {
                Console.WriteLine($"Sudoku kan niet worden opgelost omdat: {ex.Message}");
            }
        }
Exemplo n.º 4
0
        public void RoseNonogramTest()
        {
            var Rows = new List <List <int> >()
            {
                new List <int>()
                {
                    5
                },
                new List <int>()
                {
                    5
                },
                new List <int>()
                {
                    5
                },
                new List <int>()
                {
                    3
                },
                new List <int>()
                {
                    1
                },
            };

            var Columns = new List <List <int> >()
            {
                new List <int>()
                {
                    3
                },
                new List <int>()
                {
                    4
                },
                new List <int>()
                {
                    5
                },
                new List <int>()
                {
                    4
                },
                new List <int>()
                {
                    3
                },
            };

            Puzzle puzzle = new Puzzle(Rows, Columns);

            FieldType[,] matrixSolution =
            {
                { solid, solid, solid, solid, solid },
                { solid, solid, solid, solid, solid },
                { solid, solid, solid, solid, solid },
                { white, solid, solid, solid, white },
                { white, white, solid, white, white },
            };

            var solvedPuzzle = SolverEngine.Solve(puzzle);

            var solvedPuzzleMatrix = solvedPuzzle.Matrix.Fields;

            TestResult(matrixSolution, solvedPuzzleMatrix);
        }
Exemplo n.º 5
0
        public void FlamingoNonogramTest()
        {
            var Rows = new List <List <int> >()
            {
                new List <int>()
                {
                    4
                },
                new List <int>()
                {
                    6
                },
                new List <int>()
                {
                    3, 3
                },
                new List <int>()
                {
                    7
                },
                new List <int>()
                {
                    7
                },
                new List <int>()
                {
                    1, 3
                },
                new List <int>()
                {
                    3
                },
                new List <int>()
                {
                    3, 5
                },
                new List <int>()
                {
                    4, 7
                },
                new List <int>()
                {
                    13
                },
                new List <int>()
                {
                    13
                },
                new List <int>()
                {
                    13
                },
                new List <int>()
                {
                    13
                },
                new List <int>()
                {
                    13
                },
                new List <int>()
                {
                    11
                }
            };

            var Columns = new List <List <int> >()
            {
                new List <int>()
                {
                    4
                },
                new List <int>()
                {
                    4
                },
                new List <int>()
                {
                    5, 6
                },
                new List <int>()
                {
                    2, 2, 9
                },
                new List <int>()
                {
                    15
                },
                new List <int>()
                {
                    15
                },
                new List <int>()
                {
                    5, 6
                },
                new List <int>()
                {
                    7
                },
                new List <int>()
                {
                    8
                },
                new List <int>()
                {
                    8
                },
                new List <int>()
                {
                    8
                },
                new List <int>()
                {
                    8
                },
                new List <int>()
                {
                    8
                },
                new List <int>()
                {
                    7
                },
                new List <int>()
                {
                    5
                }
            };

            Puzzle puzzle = new Puzzle(Rows, Columns);

            FieldType[,] matrixSolution =
            {
                { white, white, solid, solid, solid, solid, white, white, white, white, white, white, white, white, white },
                { white, solid, solid, solid, solid, solid, solid, white, white, white, white, white, white, white, white },
                { solid, solid, solid, white, solid, solid, solid, white, white, white, white, white, white, white, white },
                { solid, solid, solid, solid, solid, solid, solid, white, white, white, white, white, white, white, white },
                { solid, solid, solid, solid, solid, solid, solid, white, white, white, white, white, white, white, white },
                { solid, white, white, white, solid, solid, solid, white, white, white, white, white, white, white, white },
                { white, white, white, solid, solid, solid, white, white, white, white, white, white, white, white, white },
                { white, white, white, solid, solid, solid, white, white, solid, solid, solid, solid, solid, white, white },
                { white, white, solid, solid, solid, solid, white, solid, solid, solid, solid, solid, solid, solid, white },
                { white, white, solid, solid, solid, solid, solid, solid, solid, solid, solid, solid, solid, solid, solid },
                { white, white, solid, solid, solid, solid, solid, solid, solid, solid, solid, solid, solid, solid, solid },
                { white, white, solid, solid, solid, solid, solid, solid, solid, solid, solid, solid, solid, solid, solid },
                { white, white, solid, solid, solid, solid, solid, solid, solid, solid, solid, solid, solid, solid, solid },
                { white, white, solid, solid, solid, solid, solid, solid, solid, solid, solid, solid, solid, solid, solid },
                { white, white, white, solid, solid, solid, solid, solid, solid, solid, solid, solid, solid, solid, white },
            };

            var solvedPuzzle = SolverEngine.Solve(puzzle);

            var solvedPuzzleMatrix = solvedPuzzle.Matrix.Fields;

            TestResult(matrixSolution, solvedPuzzleMatrix);
        }
Exemplo n.º 6
0
        public void LionNonogramTest()
        {
            var Rows = new List <List <int> >()
            {
                new List <int>()
                {
                    7
                },
                new List <int>()
                {
                    9
                },
                new List <int>()
                {
                    2, 4, 2
                },
                new List <int>()
                {
                    2, 2
                },
                new List <int>()
                {
                    2, 1, 1, 2
                },
                new List <int>()
                {
                    3, 2
                },
                new List <int>()
                {
                    2, 2
                },
                new List <int>()
                {
                    3, 3, 1
                },
                new List <int>()
                {
                    9, 1
                },
                new List <int>()
                {
                    9, 1
                },
                new List <int>()
                {
                    11, 2
                },
                new List <int>()
                {
                    15
                },
                new List <int>()
                {
                    14
                },
                new List <int>()
                {
                    2, 3, 2
                },
                new List <int>()
                {
                    1, 1, 1, 1, 1, 1, 1
                },
            };

            var Columns = new List <List <int> >()
            {
                new List <int>()
                {
                    4
                },
                new List <int>()
                {
                    6, 4
                },
                new List <int>()
                {
                    12, 1
                },
                new List <int>()
                {
                    2, 1, 6
                },
                new List <int>()
                {
                    2, 5, 1
                },
                new List <int>()
                {
                    3, 1, 6
                },
                new List <int>()
                {
                    3, 7
                },
                new List <int>()
                {
                    3, 6
                },
                new List <int>()
                {
                    3, 1, 5, 1
                },
                new List <int>()
                {
                    2, 6
                },
                new List <int>()
                {
                    12, 1
                },
                new List <int>()
                {
                    6, 4
                },
                new List <int>()
                {
                    4
                },
                new List <int>()
                {
                    3
                },
                new List <int>()
                {
                    5
                },
            };

            Puzzle puzzle = new Puzzle(Rows, Columns);

            FieldType[,] matrixSolution =
            {
                { white, white, white, solid, solid, solid, solid, solid, solid, solid, white, white, white, white, white },
                { white, white, solid, solid, solid, solid, solid, solid, solid, solid, solid, white, white, white, white },
                { white, solid, solid, white, white, solid, solid, solid, solid, white, solid, solid, white, white, white },
                { white, solid, solid, white, white, white, white, white, white, white, solid, solid, white, white, white },
                { white, solid, solid, white, white, solid, white, white, solid, white, solid, solid, white, white, white },
                { white, solid, solid, solid, white, white, white, white, white, white, solid, solid, white, white, white },
                { white, solid, solid, white, white, white, white, white, white, white, solid, solid, white, white, white },
                { white, solid, solid, solid, white, white, white, white, white, solid, solid, solid, white, white, solid },
                { white, white, solid, solid, solid, solid, solid, solid, solid, solid, solid, white, white, white, solid },
                { white, white, solid, solid, solid, solid, solid, solid, solid, solid, solid, white, white, white, solid },
                { white, solid, solid, solid, solid, solid, solid, solid, solid, solid, solid, solid, white, solid, solid },
                { solid, solid, solid, solid, solid, solid, solid, solid, solid, solid, solid, solid, solid, solid, solid },
                { solid, solid, solid, solid, solid, solid, solid, solid, solid, solid, solid, solid, solid, solid, white },
                { solid, solid, white, white, white, solid, solid, solid, white, white, white, solid, solid, white, white },
                { solid, white, solid, white, solid, white, solid, white, solid, white, solid, white, solid, white, white },
            };

            var solvedPuzzle = SolverEngine.Solve(puzzle);

            var solvedPuzzleMatrix = solvedPuzzle.Matrix.Fields;

            TestResult(matrixSolution, solvedPuzzleMatrix);
        }