public override Maybe <Hand> IsMatch(IEnumerable <Card> cards) { ThrowIfDuplicate(cards); if (cards.Count() < 5) { return(Maybe <Hand> .None); } List <Card> highPair = HandHelper.GetOfAKind(cards, 2); List <Card> remaining = HandHelper.GetRemainingCards(cards, highPair); List <Card> lowPair = HandHelper.GetOfAKind(remaining, 2); List <Card> twoPairs = highPair.Concat(lowPair).ToList(); if (twoPairs.Count != 4) { return(Maybe <Hand> .None); } List <Card> highCards = HandHelper.GetRemainingCards(cards, twoPairs); Card highCard = highCards.OrderByDescending(c => c.Value).First(); List <Card> finalCards = new List <Card>(twoPairs); finalCards.Add(highCard); return(CreateCopy <Hand>(finalCards)); }
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> treeOfAKind = HandHelper.GetOfAKind(cards, 3);; if (treeOfAKind.Count != 3) { return(Maybe <Hand> .None); } List <Card> remainingCard = cards.ToList() .FindAll(c => c.Value != treeOfAKind.First().Value); List <Card> pair = HandHelper.GetOfAKind(remainingCard, 2); if (pair.Count != 2) { return(Maybe <Hand> .None); } List <Card> finalCards = new List <Card>(treeOfAKind); finalCards.AddRange(pair); return(CreateCopy <Hand>(finalCards)); }
public override Maybe <Hand> IsMatch(IEnumerable <Card> cards) { ThrowIfDuplicate(cards); if (cards.Count() == 0) { return(Maybe <Hand> .None); } List <Card> highCards = HandHelper.GetHighCards(cards); return(CreateCopy <Hand>(highCards)); }
public override Maybe <Hand> IsMatch(IEnumerable <Card> cards) { ThrowIfDuplicate(cards); if (cards.Count() < 5) { return(Maybe <Hand> .None); } List <Card> cardsInSuit = HandHelper.GetSuitedCards(cards); if (cardsInSuit.Count != 5) { return(Maybe <Hand> .None); } return(CreateCopy <Hand>(cardsInSuit)); }
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)); }
public override Maybe <Hand> IsMatch(IEnumerable <Card> cards) { ThrowIfDuplicate(cards); if (cards.Count() < 2) { return(Maybe <Hand> .None); } List <Card> pair = HandHelper.GetOfAKind(cards, 2); if (pair.Count != 2) { return(Maybe <Hand> .None); } List <Card> highCards = HandHelper.GetHighCards(cards, pair); List <Card> finalCards = new List <Card>(pair); finalCards.AddRange(highCards); return(CreateCopy <Hand>(finalCards)); }
public override Maybe <Hand> IsMatch(IEnumerable <Card> cards) { ThrowIfDuplicate(cards); if (cards.Count() < 5) { return(Maybe <Hand> .None); } List <Card> fourOfAKind = HandHelper.GetOfAKind(cards, 4); if (fourOfAKind.Count != 4) { return(Maybe <Hand> .None); } List <Card> highCards = HandHelper.GetHighCards(cards, fourOfAKind); List <Card> finalCards = new List <Card>(fourOfAKind); finalCards.Add(highCards.First()); return(CreateCopy <Hand>(finalCards)); }
public override Maybe <Hand> IsMatch(IEnumerable <Card> cards) { ThrowIfDuplicate(cards); if (cards.Count() < 5) { return(Maybe <Hand> .None); } List <Card> threeOfAKind = HandHelper.GetOfAKind(cards, 3); if (threeOfAKind.Count != 3) { return(Maybe <Hand> .None); } List <Card> highCards = HandHelper.GetHighCards(cards, threeOfAKind); List <Card> finalCards = new List <Card>(threeOfAKind); finalCards.AddRange(highCards); return(CreateCopy <Hand>(finalCards)); }
protected void ThrowIfDuplicate(IEnumerable <Card> cards) { HandHelper.ThrowIfDuplicate(cards); }