/// <summary>
        /// Checks how many equal colors, withous repetitions, are in common with both rows
        /// </summary>
        /// <param name="row">The other row to compare</param>
        /// <returns>Number of similar colors, without repetitions</returns>
        internal int EqualColors(ColoredPegRow row)
        {
            if (this.NumberPegs != row.NumberPegs)
            {
                throw new MastermindColoredPegRowException("To compare objects, the number of pegs must be equal");
            }

            List <PegColor> foundColors = new List <PegColor>();

            for (int i = 0; i < this.NumberPegs; i++)
            {
                if (!foundColors.Contains(this.Pegs[i]))
                {
                    bool     newColor = false;
                    PegColor current  = this.Pegs[i];

                    foreach (PegColor color in row.Pegs)
                    {
                        if (current == color)
                        {
                            newColor = true;
                            break;
                        }
                    }

                    if (newColor)
                    {
                        foundColors.Add(current);
                    }
                }
            }

            return(foundColors.Count);
        }
Example #2
0
 void Start()
 {
     CS     = GameObject.Find("SceneController2").GetComponent <CreateStim>();
     Colors = gameObject.GetComponent <PegColor> ();
 }