コード例 #1
0
 public void Setup()
 {
     _codePegsToGuess = new List <CodePeg>()
     {
         CodePeg.Black, CodePeg.Black, CodePeg.Green, CodePeg.White
     };
     _mastermind = new GoFlow.Mastermind.Mastermind(_codePegsToGuess);
 }
コード例 #2
0
ファイル: Program.cs プロジェクト: Morzkat/GoFlowTest
        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++;
            }
        }