private static bool PlayerHasFlushHand(List <Card> cards) { Dictionary <Suit, int> countsOfcardsBySuit = HandUtils.GetCountsOfCardsBySuit(cards); foreach (int count in countsOfcardsBySuit.Values) { if (count >= cardsInHand) { return(true); } } return(false); }
private static bool PlayerHasPairHand(List <Card> cards) { Dictionary <CardValue, int> countOfCardsByValue = HandUtils.GetCountsOfCardsByValue(cards); foreach (int count in countOfCardsByValue.Values) { if (count >= cardsInPair) { return(true); } } return(false); }
public static List <Card> GetHighestValueFlush(List <Card> cards, int numberOfCardsForFlush) { Dictionary <Suit, int> countsOfCardsBySuit = GetCountsOfCardsBySuit(cards); List <Suit> suitsWithFlush = new List <Suit>(); foreach (KeyValuePair <Suit, int> count in countsOfCardsBySuit) { if (count.Value >= numberOfCardsForFlush) { suitsWithFlush.Add(count.Key); } } if (suitsWithFlush.Count == 0) { throw new Exception("Expected cards to be flush but was not"); } else if (suitsWithFlush.Count == 1) { List <Card> flushCards = HandUtils.GetCardsMatchingSuit(suitsWithFlush[0], cards); return(HandUtils.GetHighestValueSortedSubset(numberOfCardsForFlush, flushCards)); } else { Dictionary <Suit, List <Card> > validFlushSets = new Dictionary <Suit, List <Card> >(); foreach (Suit suit in suitsWithFlush) { List <Card> flushCards = HandUtils.GetCardsMatchingSuit(suit, cards); flushCards = HandUtils.GetHighestValueSortedSubset(numberOfCardsForFlush, flushCards); validFlushSets.Add(suit, flushCards); } List <Card> bestFlush = null; foreach (List <Card> flush in validFlushSets.Values) { if (bestFlush == null || HandUtils.CompareSortedCardLists(flush, bestFlush) > 0) { bestFlush = flush; } } return(bestFlush); } }