Ejemplo n.º 1
0
        public IEnumerable<Card> Match(IEnumerable<Card> cardsToMatch)
        {
            var nofAKind = new NofAKind();
            var threeOfAKind = nofAKind.Find(cardsToMatch, 3);

            if (threeOfAKind != null)
            {
                var restOfTheCards = cardsToMatch.Except(threeOfAKind);

                IEnumerable<Card> currentPair, highestPair = null;

                while ((currentPair = nofAKind.Find(restOfTheCards, 2)) != null)
                {
                    if (highestPair == null
                        || currentPair.First().Rank > highestPair.First().Rank)
                    {
                        highestPair = currentPair;
                        restOfTheCards = restOfTheCards.Except(currentPair);
                    }
                }

                return highestPair != null ? threeOfAKind.Union(highestPair) : null;
            }

            return null;
        }
Ejemplo n.º 2
0
        public IEnumerable<Card> Match(IEnumerable<Card> cardsToMatch)
        {
            var nofAKind = new NofAKind();

            var three = nofAKind.Find(cardsToMatch, 3);
            if (three != null)
            {
                var nextThree = nofAKind.Find(cardsToMatch.Except(three), 3);

                return nextThree ?? three;
            }

            return null;
        }
Ejemplo n.º 3
0
        public IEnumerable<Card> Match(IEnumerable<Card> cardsToMatch)
        {
            var nofAKind = new NofAKind();
            var firstPair = nofAKind.Find(cardsToMatch, 2);
            if (firstPair == null)
            {
                return null;
            }

            var secondPair = nofAKind.Find(cardsToMatch.Except(firstPair), 2);
            if (secondPair == null)
            {
                return null;
            }

            return firstPair.Union(secondPair);
        }