Exemple #1
0
        public Program()
        {
            this.gameCount   = 20;
            this.recordStore = null;
            this.readingMode = false;

            this.AmountHigh = this.AmountLow = 0;
        }
Exemple #2
0
        /// <summary>
        /// Parse the arguments from command line:
        ///     BlackJackTraining [-g (GameCount)] [-s] [-r (FilePath)]
        ///
        ///     -g : Set the game count to simulate.
        ///     -s : Save game result to file instead of console print-out.
        ///     -r : Read and print out saved game result from given file path.
        /// </summary>
        /// <param name="args"></param>
        /// <param name="errorMsg"></param>
        /// <returns></returns>
        public bool ParseArguments(string[] args, out string errorMsg)
        {
            string context = null;

            errorMsg = string.Empty;

            foreach (var argument in args)
            {
                if (!string.IsNullOrEmpty(context))
                {
                    if (context.StartsWith("-g"))
                    {
                        if (!int.TryParse(argument, out this.gameCount))
                        {
                            errorMsg = string.Format("Expect integer value for {0}. But input is {1}.", context, argument);
                            return(false);
                        }
                    }
                    else if (context.StartsWith("-r"))
                    {
                        this.recordStore = new LiteGameRecordStore(argument);
                        this.readingMode = true;
                    }
                }
                else
                {
                    string cmdArg = argument.ToLower();

                    if (cmdArg.StartsWith("-s"))
                    {
                        string storeFile =
                            string.Format(
                                @"{0}\{1}_{2:yy}{2:MM}{2:dd}_{3}",
                                Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location),
                                "ResultStore",
                                DateTime.Now,
                                Convert.ToBase64String(Guid.NewGuid().ToByteArray()).Replace('/', '-'));

                        this.recordStore = new LiteGameRecordStore(storeFile);
                    }
                    else
                    {
                        context = cmdArg;
                    }
                }
            }

            return(true);
        }