Esempio n. 1
0
        public bool isSame(Guess g)
        {
            if (g.getNumSpaces() != this.numSpaces)
            {
                return(false);
            }
            bool sameColors = true;

            for (int i = 0; i < numSpaces; i++)
            {
                if (g.getColor(i) != this.getColor(i))
                {
                    sameColors = false;
                }
            }
            return(sameColors);
        }
Esempio n. 2
0
        public int[] compare(Guess g)
        {
            int[] result = new int[2];
            result[0] = 0;
            result[1] = 0;
            if (g.getNumSpaces() != this.numSpaces)
            {
                MessageBox.Show("comparing two guess with different numbers of spaces.");
                return(result);
            }

            // count same color same place
            for (int i = 0; i < numSpaces; i++)
            {
                if (g.getColor(i) == getColor(i))
                {
                    result[0] = result[0] + 1;
                }
            }

            // count same color different place
            // for this we need to get the intersection of the two color arrays
            // keeping duplicates
            // got this from http://stackoverflow.com/questions/5011948/how-do-i-do-an-integer-list-intersection-while-keeping-duplicates
            ILookup <System.Drawing.Color, System.Drawing.Color> lookup1 = colors.ToLookup(i => i);
            List <System.Drawing.Color> tempOther = new List <System.Drawing.Color>();

            for (int i = 0; i < numSpaces; i++)
            {
                tempOther.Add(g.getColor(i));
            }
            ILookup <System.Drawing.Color, System.Drawing.Color> lookup2 = tempOther.ToLookup(i => i);

            System.Drawing.Color[] intersection = (
                from group1 in lookup1
                let group2 = lookup2[group1.Key]
                             where group2.Any()
                             let smallerGroup = group1.Count() < group2.Count() ? group1 : group2
                                                from i in smallerGroup
                                                select i
                ).ToArray();
            result[1] = intersection.Count() - result[0];
            return(result);
        }
Esempio n. 3
0
 public bool isSameNumSpaces(Guess g)
 {
     return(g.getNumSpaces() == this.numSpaces);
 }