Exemplo n.º 1
0
        public void Mastermind_First_Test_Case()
        {
            var guessCodePegs = new List <CodePeg>()
            {
                CodePeg.Black, CodePeg.Black, CodePeg.Green, CodePeg.White
            };                                                                                                      //Black, Black, Black, Black
            var expectedResult = new List <ResultPeg>()
            {
                ResultPeg.Black, ResultPeg.Black, ResultPeg.Black, ResultPeg.Black
            };

            var result = _mastermind.GetHints(guessCodePegs);

            Assert.AreEqual(expectedResult, result);
        }
Exemplo n.º 2
0
        public static void PlayMasterMind()
        {
            var attemps         = 0;
            var positions       = 4;
            var codePegs        = (CodePeg[])Enum.GetValues(typeof(CodePeg));
            var codePegsToGuess = new List <CodePeg>()
            {
                CodePeg.Red, CodePeg.Black, CodePeg.Green, CodePeg.White
            };

            // codePegsToGuess.AddRange(codePegs.Randomize().Take(positions));

            foreach (CodePeg codePeg in codePegs)
            {
                Console.WriteLine($"{codePeg}: {(int)codePeg}");
            }

            while (attemps < 1)
            {
                var guessCodePegs = new List <CodePeg>();

                for (int position = 1; position <= positions; position++)
                {
                    Console.WriteLine($"Select a color for the position {position}: ");
                    int.TryParse(Console.ReadLine(), out int guessCodePeg);
                    try
                    {
                        guessCodePegs.Add(codePegs[guessCodePeg]);
                    }
                    catch
                    {
                        guessCodePegs.Add(codePegs[0]);
                    }
                }

                Mastermind mastermind  = new Mastermind(codePegsToGuess);
                var        hints       = mastermind.GetHints(guessCodePegs);
                var        guessedPegs = 0;

                foreach (var hint in hints)
                {
                    if (hint == ResultPeg.Black)
                    {
                        guessedPegs++;
                    }

                    Console.WriteLine(hint);
                }

                if (guessedPegs == guessCodePegs.Count)
                {
                    Console.WriteLine($"Well done, you broke the code in {attemps} attemps.");
                    break;
                }

                attemps++;
            }
        }