예제 #1
0
        public List <int> RunBatch(string type)
        {
            Counter    c;
            List <int> tries = new List <int>();

            for (int i = 1; i < 101; i++)
            {
                GuessingGame gg = new GuessingGame(i, 1, 100);
                if (type == "random")
                {
                    c = new Counter(new RandomGuesser());
                }
                else if (type == "elim")
                {
                    c = new Counter(new GuesserElim(gg.Min, gg.Max));
                }
                else if (type == "merge")
                {
                    c = new Counter(new BinaryGuesser(gg.Min, gg.Max, gg));
                }
                else
                {
                    c = new Counter(new RandomGuesser());
                }

                int attempt = c.CountTries(gg);
                tries.Add(attempt);
            }
            PrintListInfo(tries, type);
            return(tries);
        }
예제 #2
0
        public int CountTries(GuessingGame gg)
        {
            GuessQuality output = GuessQuality.Start;
            int          tries  = 0;

            while (output != GuessQuality.Match)
            {
                tries++;
                int guess = g.GenerateGuess();
                output      = gg.MakeGuess(guess);
                g.LastGuess = output;
            }

            return(tries);
        }
예제 #3
0
        public void PlayGame()
        {
            GuessQuality output = GuessQuality.TooLow;

            while (output != GuessQuality.Match)
            {
                GuessingGame gg = new GuessingGame();
                Console.WriteLine("Please input a number between 1 and 100:");
                int input = int.Parse(Console.ReadLine());
                output = gg.MakeGuess(input);
                Console.WriteLine(output);
                if (output == GuessQuality.Match)
                {
                    Console.WriteLine("You win!!!");
                }
            }
        }
예제 #4
0
 public BinaryGuesser(int min, int max, GuessingGame gg)
 {
     this.min = min;
     this.max = max;
     this.gg  = gg;
 }