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; }
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; }
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); }