Exemplo n.º 1
0
        public KeyValuePair <int, ResultPeg> GetHint(CodePeg codePeg, int codePegIndex, Dictionary <int, ResultPeg> hints)
        {
            var totalCodesPegs = codes.Count;
            var hint           = new KeyValuePair <int, ResultPeg>(codePegIndex, hints[codePegIndex]);

            for (int i = 0; i < totalCodesPegs; i++)
            {
                if (codePeg == codes[i])
                {
                    if (codePegIndex == i)
                    {
                        return(new KeyValuePair <int, ResultPeg>(i, ResultPeg.Black));
                    }

                    hints.TryGetValue(i, out ResultPeg peg);

                    if (peg == ResultPeg.Black)
                    {
                        continue;
                    }
                    if (peg == ResultPeg.None)
                    {
                        hint = new KeyValuePair <int, ResultPeg>(i, ResultPeg.White);
                    }
                }
            }
            return(hint);
        }
Exemplo n.º 2
0
        public void PlayTheGame()
        {
            List <CodePeg> copiedCodePegsPlayer1      = new List <CodePeg>(codePegsPlayer1);
            string         letterCodedCodePegsPlayer2 = "";

            Console.WriteLine("Enter four-color guess; R for Red, G for Green, C for Cyan, Y for Yellow, B for Black, W for White)\n" +
                              "eg. RCRW ");

            while (true)
            {
                copiedCodePegsPlayer1.Clear();
                copiedCodePegsPlayer1 = codePegsPlayer1.ToList();

                Console.WriteLine("Your last guess was: " + letterCodedCodePegsPlayer2);
                codePegsPlayer2.Clear();

                letterCodedCodePegsPlayer2 = Console.ReadLine();
                List <string> stringlist = new List <string>(letterCodedCodePegsPlayer2.Select(c => c.ToString()));

                foreach (string str in stringlist)
                {
                    CodePeg singleCodePeg = new CodePeg();
                    Enum.TryParse(str, out singleCodePeg);
                    codePegsPlayer2.Add(singleCodePeg);
                }

                var gameRound = new GameRound(copiedCodePegsPlayer1, codePegsPlayer2);
                gameRound.PrintTheAssessmentResult();
            }
        }
Exemplo n.º 3
0
        public CodePeg GetRandomCodePeg()
        {
            Random  rnd     = new Random();
            int     mIndex  = rnd.Next(Enum.GetNames(typeof(CodePeg)).Length);
            CodePeg codePeg = (CodePeg)mIndex;

            return(codePeg);
        }
Exemplo n.º 4
0
        public void ShouldCreateShieldWhenCodeMakerPlaysValidShield()
        {
            //Arrange
            var boardConfig   = new BoardConfig(4, 10);
            var decodingBoard = new DecodingBoard(boardConfig);

            var colors = new CodePeg[4];
            var shield = new Shield(colors);

            //Act
            decodingBoard.CodeMaker(shield);

            //Assert
            decodingBoard.Shield.Should().NotBeNull();
            decodingBoard.Shield.Should().Be(shield);
        }
Exemplo n.º 5
0
        public void ShouldThrowArgumentExceptionWhenCodeMakerShieldIsDifferentThanConfig(int shieldSize)
        {
            //Arrange
            var boardConfig   = new BoardConfig(4, 10);
            var decodingBoard = new DecodingBoard(boardConfig);

            var colors = new CodePeg[shieldSize];
            var shield = new Shield(colors);

            //Act
            void Action() => decodingBoard.CodeMaker(shield);

            var exception = Record.Exception(Action);

            //Assert
            exception.Should().BeOfType <ArgumentException>();
        }
Exemplo n.º 6
0
 private ResultPeg ValidateTwoCodePeg(CodePeg main, CodePeg comparation)
 {
     try
     {
         if (main == comparation)
         {
             return(ResultPeg.Black);
         }
         else
         {
             return(ResultPeg.White);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine(string.Format("{0} - {1} --> {2}", "Mastermind", "ValidateTwoCodePeg", ex.Message));
         return(ResultPeg.None);
     }
 }
Exemplo n.º 7
0
 public bool HasColorAt(int index, CodePeg color)
 {
     return(this[index] == color);
 }