static void Main(string[] args)
        {
            SudokuWriter sudokuWriter = new SudokuWriter();
            ImmutableSudokuGrid filledGrid = sudokuWriter.CreateFilledGrid();
            filledGrid.PrintGrid();

            Console.WriteLine("\n");

            ImmutableSudokuGrid emptiedGrid = sudokuWriter.EmptyGridForHardSolve(filledGrid);
            emptiedGrid.PrintGrid();

            Console.WriteLine("\n");

            SudokuGrid mutableEmptiedGrid = emptiedGrid.MakeMutableCopy();
            SudokuSolver sudokuSolver = new SudokuSolver();
            sudokuSolver.Solve(mutableEmptiedGrid);
            mutableEmptiedGrid.PrintGrid();

            if (mutableEmptiedGrid.FindAllEmptySquares().Count != 0)
            {
                Console.WriteLine("\n");
                HarderSudokuSolver harderSolver = new HarderSudokuSolver();
                ImmutableSudokuGrid solvedGrid = harderSolver.Solve(emptiedGrid);
                solvedGrid.PrintGrid();
            }
        }
Beispiel #2
0
        private ImmutableSudokuGrid EmptyGridForHardSolve(ImmutableSudokuGrid inputGrid, HarderSudokuSolver solver)
        {
            ImmutableSudokuGrid grid = EmptyGridForSimpleSolve(inputGrid);
            var listOfFilledSquares = grid.FindAllFilledSquares();
            for (int i = 0; i < listOfFilledSquares.Count; i++)
            {
                var square = listOfFilledSquares[i];
                bool isNotUniqueValue = solver.CanBeSolvedWithDifferentValueInSquare(grid, square, grid.Elements[square.Row, square.Column]);

                if (!isNotUniqueValue)
                {
                    grid = grid.WithoutSquare(square);
                    return EmptyGridForHardSolve(grid);
                }
            }

            return grid;
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Do you want me to try and solve an Easy Sudoku (type 1) or a Very Hard Sudoku (type 2)?");
            string difficulty = Console.ReadLine();
            if (difficulty == "1") { difficulty = "Easy" ; }
            else if (difficulty == "2") { difficulty = "VeryHard"; }
            else
            {
                Console.WriteLine("Stop being difficult.  I'm going to solve an easy one then...");
                difficulty = "Easy";
            }

            ImmutableSudokuGrid grid = new ImmutableSudokuGrid(@"..\..\..\" + difficulty + @"Sudoku.txt");

            if (grid.Elements == null)
            {
                Console.WriteLine("Error, cannot read grid from file.");
                return;
            }

            HarderSudokuSolver sudokuSolver = new HarderSudokuSolver();
            sudokuSolver.Solve(grid).PrintGrid();
        }
Beispiel #4
0
 private ImmutableSudokuGrid CreateFilledGrid(HarderSudokuSolver solver)
 {
     ImmutableSudokuGrid sudokuGrid = new ImmutableSudokuGrid();
     return solver.Solve(sudokuGrid, true);
 }
Beispiel #5
0
        private ImmutableSudokuGrid EmptyGridForHardSolve(ImmutableSudokuGrid inputGrid, HarderSudokuSolver solver)
        {
            ImmutableSudokuGrid grid = EmptyGridForSimpleSolve(inputGrid);
            var listOfFilledSquares  = grid.FindAllFilledSquares();

            for (int i = 0; i < listOfFilledSquares.Count; i++)
            {
                var  square           = listOfFilledSquares[i];
                bool isNotUniqueValue = solver.CanBeSolvedWithDifferentValueInSquare(grid, square, grid.Elements[square.Row, square.Column]);

                if (!isNotUniqueValue)
                {
                    grid = grid.WithoutSquare(square);
                    return(EmptyGridForHardSolve(grid));
                }
            }

            return(grid);
        }
Beispiel #6
0
        private ImmutableSudokuGrid CreateFilledGrid(HarderSudokuSolver solver)
        {
            ImmutableSudokuGrid sudokuGrid = new ImmutableSudokuGrid();

            return(solver.Solve(sudokuGrid, true));
        }
 public void InitializeTests()
 {
     sudokuSolver = new HarderSudokuSolver();
 }