Ejemplo n.º 1
0
        public void Init(string[] lines)
        {
            Lines      = lines;
            numbersOPS = new Stopwatch();
            numbersOP  = new Stopwatch();
            SolverOPS  = new NumbersOnePossibilitySolver();
            SolverOP   = new NumbersOnePlace();

            List <char> Puzzle = new List <Char>();

            if (lines[0] == "4")
            {
                board           = new FourBoard();
                board.BoardSize = 4;
            }
            if (lines[0] == "9")
            {
                board           = new NineBoard();
                board.BoardSize = 9;
            }
            for (int i = 2; i < lines.Length; i++)
            {
                ParseSudokuPuzzle.ParsePuzzleLine(lines[i], Puzzle);
            }
            board.Init(Puzzle);
        }
Ejemplo n.º 2
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++;
            }
        }