public override Maybe <Hand> IsMatch(IEnumerable <Card> cards) { ThrowIfDuplicate(cards); if (cards.Count() < 5) { return(Maybe <Hand> .None); } List <Card> cardsInSuit = HandHelper.GetSuitedCards(cards, 5, true); if (cardsInSuit.Count < 5) { return(Maybe <Hand> .None); } List <Card> straightFlushCards = HandHelper.ResolveStraight(cardsInSuit); if (straightFlushCards.Count != 5) { return(Maybe <Hand> .None); } return(CreateCopy <Hand>(straightFlushCards)); }
public override Maybe <Hand> IsMatch(IEnumerable <Card> cards) { ThrowIfDuplicate(cards); if (cards.Count() < 5) { return(Maybe <Hand> .None); } List <Card> pairs = cards.GroupBy(s => s.Value) .Where(g => g.Count() == 2) .SelectMany(grp => grp) .OrderBy(c => c.Value) .ToList(); List <Card> pairsRemoved = new List <Card>(cards); //TODO: Improve if (pairs.Count >= 2) { pairsRemoved.Remove(pairs.Take(1).First()); } if (pairs.Count >= 4) { pairsRemoved.Remove(pairs.Skip(2).Take(1).First()); } List <Card> cardsInStraight = pairsRemoved .OrderByDescending(c => c.Value) .ToList(); List <Card> straight = HandHelper.ResolveStraight(cardsInStraight); if (straight.Count != 5) { return(Maybe <Hand> .None); } return(CreateCopy <Hand>(straight)); }