Exemplo n.º 1
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.º 2
0
        /// <summary>
        /// Manager that will handle running the list cmdline options and return a status code to the caller.
        /// </summary>
        /// <param name="opts"><see cref="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));
            }

            // Validate Input
            ValidateCmdLine val = new ValidateCmdLine();

            val.IsCmdLineValid(opts);

            await Task.Run(() =>
            {
                Node rootNode = Helpers.CreateRandomList(opts.Length);
                Node dupNode  = Node.DuplicateList(rootNode);
                Helpers.PrintLists(rootNode, dupNode);
            });

            return(Consts.c_exitCodeSuccess);
        }