public static bool HasXOfAKind <T>(this IGambleCardHand <T> self, int x) where T : IGambleCard { if (x < 1) { //if x <= 0, then this is useless to call, still we return false return(false); } Dictionary <GambleCardFace, int> occurences = self.GetValueOccurenceCount(); foreach (GambleCardFace key in occurences.Keys) { if (occurences[key] >= x) { return(true); } } return(false); }
public static bool HasXConsecutive <T>(this IGambleCardHand <T> self, int x) where T : IGambleCard { if (x < 2) { //if x <= 1, then this is useless to call, still we return false return(false); } Dictionary <GambleCardFace, int> occurences = self.GetValueOccurenceCount(); bool found = true; for (int i = 0; i <= 13 - (x - 1); i++) { for (int j = i; j < i + x; j++) { if (j > 13) { found = false; break; } GambleCardFace current = GambleCardExtended.CalculateGambleCardValue(j); if (occurences[current] <= 0) { found = false; break; } else { found = true; } } if (found) { return(true); } } return(found); }