Пример #1
0
        public bool IsProperSubsetOf(PegSet other)
        {
            if (other == null)
            {
                throw new ArgumentNullException(nameof(other));
            }

            if (other == this)
            {
                return(false);
            }

            if (Palette != other.Palette)
            {
                return(false);
            }

            if (Size == 0)
            {
                return(other.Size > 0);
            }

            if (Size >= other.Size)
            {
                return(false);
            }

            return(Pegs.All(peg => _pegCounts[peg] <= other._pegCounts[peg]));
        }
Пример #2
0
        public GuessResult CompareTo(PegPattern other)
        {
            if (Palette != other.Palette || Size != other.Size)
            {
                throw new InvalidOperationException("Patterns must have same palette and size.");
            }

            var positionCount = Pegs
                                .Zip(other.Pegs, (a, b) => a == b)
                                .Count(x => x);

            var colorCount = Pegs
                             .Intersect(other.Pegs)
                             .Sum(x => Math.Min(_pegCounts[x], other._pegCounts[x]));

            colorCount -= positionCount;

            return(new GuessResult(positionCount, colorCount));
        }
Пример #3
0
        private void MakePegs()
        {
            PegVM pegYellow = new PegVM()
            {
                PegColor = Brushes.Yellow, Name = "Yellow"
            };
            PegVM pegGreen = new PegVM()
            {
                PegColor = Brushes.Green, Name = "Green"
            };
            PegVM pegRed = new PegVM()
            {
                PegColor = Brushes.Red, Name = "Red"
            };

            Pegs.Add(pegYellow);
            Pegs.Add(pegRed);
            Pegs.Add(pegGreen);
        }
Пример #4
0
 protected virtual bool EqualsCore(PegSet other)
 {
     return(Palette == other.Palette &&
            Size == other.Size &&
            Pegs.SequenceEqual(other.Pegs));
 }