Exemplo n.º 1
0
        public void SolveCells(Board board)
        {
            int Count = 0;

            while (!Solved && Count < 81)
            {
                if (board.BoardSize == 9)
                {
                    testBoard = board;
                    //ParseSudokuPuzzle.CopyBoard((NineBoard)testBoard, board);
                }

                isFirstGuess = true;
                int counter = 0;
                MakeGuess(testBoard);
                while (counter < 81)
                {
                    OnePossibilitySolver.SolveCells(testBoard);

                    if (testBoard.SolvedCells != board.BoardSize * board.BoardSize)
                    {
                        OnePlaceSolver.SolveCells(testBoard);
                    }

                    if (testBoard.SolvedCells != board.BoardSize * board.BoardSize)
                    {
                        MakeGuess(testBoard);
                    }
                    if (testBoard.SolvedCells == board.BoardSize * board.BoardSize)
                    {
                        Solved = true;
                        ParseSudokuPuzzle.CopyBoard(board, testBoard);
                    }
                    counter++;
                }
                Count++;
            }
        }
Exemplo n.º 2
0
        public void Solve()
        {
            int counter = 0;

            while (counter < _maxCounts)
            {
                numbersOPS.Start();
                SolverOPS.SolveCells(board);
                numbersOPS.Start();
                if (board.SolvedCells != board.BoardSize * board.BoardSize)
                {
                    numbersOP.Start();
                    SolverOP.SolveCells(board);
                    numbersOP.Stop();
                    if (board.SolvedCells != board.BoardSize * board.BoardSize)
                    {
                        SolverGuess.SolveCells(board);
                    }
                }
                counter++;
            }

            PrintPuzzle(numbersOPS, numbersOP, board);
        }