Ejemplo n.º 1
0
        public      PegCompareResult[] CompareTo(PegCombination p_otherCombination)
        {
            PegCombination otherCombination = new PegCombination(p_otherCombination);

            PegCompareResult[] result = new PegCompareResult[_numberofpegs];

            for (int i = 0; i < _numberofpegs; i++)
            {
                if (this._color[i] == otherCombination._color[i])
                {
                    result[i] = PegCompareResult.MatchColorAndPosition;
                    otherCombination._color[i] = PegColors.Unassigned;
                }
                else
                {
                    result[i] = PegCompareResult.NoMatch;
                }
            }

            for (int i = 0; i < _numberofpegs; i++)
            {
                if (otherCombination.ContainsColor(this._color[i]))
                {
                    result[i] = PegCompareResult.MatchColor;
                    otherCombination.RemoveFirstOfColor(this._color[i]);
                }
            }

            return(result);
        }
Ejemplo n.º 2
0
        public bool IsPlausibleFor(PegCombination p_combination)
        {
            int colorMatchesLeft    = this._colorMatches;
            int positionMatchesLeft = this._positionMatches;

            for (int i = 0; i < _result.Length; i++)
            {
                if (_combination.ContainsColor(p_combination._color[i]))
                {
                    if (_combination._color[i] == p_combination._color[i])
                    {
                        if (positionMatchesLeft > 0)
                        {
                            positionMatchesLeft--;
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        if (colorMatchesLeft > 0)
                        {
                            colorMatchesLeft--;
                        }
                        else
                        {
                            return(false);
                        }
                    }
                }
            }
            if (colorMatchesLeft > 0)
            {
                return(false);
            }
            if (positionMatchesLeft > 0)
            {
                return(false);
            }
            return(true);
        }