Exemplo n.º 1
0
        public SudokuGenerator(
            IGameSolver sudokuSolver,
            IGameTransformer sudokuTransformer)
        {
            if (sudokuSolver == null || sudokuTransformer == null)
            {
                throw new ArgumentNullException("SudokuSolver or sudokuTransformer is null!");
            }

            this.sudokuSolver      = sudokuSolver;
            this.sudokuTransformer = sudokuTransformer;

            this.generatedSudokuBoard = new byte[9][];
            for (int i = 0; i < 9; i++)
            {
                this.generatedSudokuBoard[i] = new byte[9];
            }

            // This generates the lexicographically smallest solved sudoku, because until this moment
            // the generatedSudokuBoard array is filled only with zeroes.
            // So we save it and later generate other sudoku boards from it by shuffling it.
            this.sudokuSolver.SolveSudoku(this.generatedSudokuBoard);

            this.sudokuBoardForPlayer = new byte[9][];
            for (int i = 0; i < 9; i++)
            {
                this.sudokuBoardForPlayer[i] = new byte[9];
            }
        }
Exemplo n.º 2
0
        public SudokuUserControl(
            IGameGenerator sudokuGenerator,
            IGameSolver sudokuSolver)
        {
            if (sudokuGenerator == null || sudokuSolver == null)
            {
                throw new ArgumentNullException("SudokuGenerator or sudokuSolver is null!");
            }

            this.sudokuGenerator = sudokuGenerator;
            this.sudokuSolver    = sudokuSolver;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Manager that will handle running the game cmdline options and return a status code to the caller.
        /// </summary>
        /// <param name="opts">CmdLineOptions object that contains the parsed command line args.</param>
        /// <returns>Error Code.  0 = Success, 1 = Failure.</returns>
        public static async Task<int> RunAndReturnExitCodeAsync(CmdLineOptions opts)
        {
            if (opts == null)
            {
                throw new ArgumentNullException(nameof(opts));
            }

            RuntimeTimer.RegisterAppStart();

            m_cmdLineOpts = opts;

            // Validate Input
            ValidateCmdLine val = new ValidateCmdLine();
            val.IsCmdLineValid(opts);

            // Load the dictionary from disk
            await LoadDictFromDiskAsync();

            await Task.Run(() =>
            {
                BoardMaker maker = new BoardMaker();
                maker.LoadRandomBoard(opts.SideLength);
                Board board = maker.GetBoard();

                IGameSolver solver = null;
                if (m_cmdLineOpts.Singlethreaded)
                {
                    solver = new SinglethreadedGameSolverService();
                }
                else
                {
                    solver = new AsyncGameSolverService();
                }
                var foundWords = solver.Solve(m_wordDict, board);

                // This is a little odd.  I want to stop timing before I write all the words, which takes a long time
                RuntimeTimer.RegisterAppEnd();

                var totalOperations = solver.GetTotalOperations();
                PrintFoundWordsToConsole(foundWords, totalOperations, opts.ForceWriteFoundWords);
            });



            return Utils.Consts.c_exitCodeSuccess;
        }
Exemplo n.º 4
0
 public void Teardown()
 {
     _solver = null;
 }
Exemplo n.º 5
0
 public void Setup()
 {
     _solver = new DeepRecursiveUndoingSolver();
 }