Esempio n. 1
0
        public (int pico, int fermi) CompareTo(BagelNumber other)
        {
            int pico  = 0;
            int fermi = 0;

            for (int i = 0; i < _digits.Length; i++)
            {
                for (int j = 0; j < other._digits.Length; j++)
                {
                    if (_digits[i] == other._digits[j])
                    {
                        if (i == j)
                        {
                            ++fermi;
                        }
                        else
                        {
                            ++pico;
                        }
                    }
                }
            }

            return(pico, fermi);
        }
Esempio n. 2
0
        private bool  PlayRound()
        {
            var secret = BagelNumber.CreateSecretNumber(Length);

            Console.WriteLine("O.K. I have a number in mind.");
            for (int guessNo = 1; guessNo <= MaxGuesses; ++guessNo)
            {
                string          strGuess;
                BagelValidation isValid;
                do
                {
                    Console.WriteLine($"Guess #{guessNo}");
                    strGuess = Console.ReadLine();
                    isValid  = BagelNumber.IsValid(strGuess, Length);
                    PrintError(isValid);
                } while (isValid != BagelValidation.Valid);

                var guess = new BagelNumber(strGuess);
                var fermi = 0;
                var pico  = 0;
                (pico, fermi) = secret.CompareTo(guess);
                if (pico + fermi == 0)
                {
                    Console.Write("BAGELS!");
                }
                else if (fermi == Length)
                {
                    Console.WriteLine("You got it!");
                    return(true);
                }
                else
                {
                    PrintList("Pico ", pico);
                    PrintList("Fermi ", fermi);
                }
                Console.WriteLine();
            }

            Console.WriteLine("Oh, well.");
            Console.WriteLine($"That's {MaxGuesses} guesses.  My Number was {secret}");

            return(false);
        }