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); }
/* * //TODO Recursion is required for this (to have X nested loops), so for now, we brute code GetStraight<T> * //Unfortunately, in the occurence of a straight or * public static IList<IList<T>> GetXConsecutive<T>(this IList<T> self, int x) where T : IGambleCard * { * List<List<T>> * allStraights = new List<List<T>>(); * if (!self.HasXConsecutive(x)) * { * return new List<IList<T>>(); * } * * Dictionary<GambleCardValue, IList<T>> * occurences = self.GetValueOccurenceList(); * * bool found = true; * for (int i = 13 - (x-1); i >= 0; i--) * { * for (int j = i + (x-1); j >= i ; j--) * { * if (j < 0) * { * found = false; * break; * } * GambleCardValue current = GambleCardExtended.CalculateGambleCardValue(j); * if (occurences[current].Count <= 0) * { * found = false; * break; * } * else * { * found = true; * } * } * if (found) * { * } * } * //We dont need to sort since we start at ACE, go to King, and then loop back down to ACE * //(We skip the last ace since we cant start with an Low-Ace, (we can with a High-Ace), because Low-Ace is the lowest card * * //Cant do an implicit conversion, and explicit didn't work last time i checked, but this does :D * IList<IList<T>> ret = new List<IList<T>>(allStraights); * return ret; * } */ //Generic Gets public static T GetHighCard <T>(this IGambleCardHand <T> self) where T : IGambleCard { if (self.Count <= 0) { return(default(T)); } Dictionary <GambleCardFace, IList <T> > occurences = self.GetValueOccurenceList(); for (int i = 13; i > 0; i--) { GambleCardFace val = GambleCardExtended.CalculateGambleCardValue(i); if (occurences[val].Count > 0) { return(occurences[val][0]); } } return(default(T)); }
public static bool HasXOfSuit <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 <GambleCardSuit, int> occurences = self.GetSuitOccurenceCount(); foreach (GambleCardSuit suit in SUITS) { if (occurences[suit] < x) { continue; } return(true); } return(false); }
public static Dictionary <GambleCardSuit, int> GetSuitOccurenceCount <T>(this IGambleCardHand <T> self) where T : IGambleCard { Dictionary <GambleCardSuit, int> occurences = new Dictionary <GambleCardSuit, int>(); foreach (GambleCardSuit suit in SUITS) { occurences.Add(suit, 0); } for (int i = 0; i < self.Count; i++) { if (self[i] == null || self[i].Face == GambleCardFace.Joker) { continue; } occurences[self[i].Suit]++; } return(occurences); }
// public static Dictionary <GambleCardFace, int> GetValueOccurenceCount <T>(this IGambleCardHand <T> self) where T : IGambleCard { Dictionary <GambleCardFace, int> occurences = new Dictionary <GambleCardFace, int>(); foreach (GambleCardFace value in VALUES) { occurences.Add(value, 0); } for (int i = 0; i < self.Count; i++) { if (self[i] == null || self[i].Face == GambleCardFace.Joker) { continue; } occurences[self[i].Face]++; } return(occurences); }
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); }
//Temporary generic explicits public static IList <IList <T> > GetXConsecutiveOfSuit <T>(this IGambleCardHand <T> self) where T : IGambleCard { IList <IList <T> > allStraights = self.GetXConsecutive(); for (int i = allStraights.Count - 1; i >= 0; i--) { IGambleCardHand <T> tempHand = new GambleCardHand <T>(allStraights[i]); IList <IList <T> > flushs = tempHand.GetXOfSuit(); if (flushs.Count <= 0) { allStraights.RemoveAt(i); } } List <IList <T> > sort = new List <IList <T> >(allStraights); sort.Sort( delegate(IList <T> x, IList <T> y) { int ret = 0; for (int i = 0; i < x.Count && i < y.Count; i++) { ret = -x[i].CompareTo(y[i]); if (ret != 0) { return(ret); } } return(-x.Count.CompareTo(y.Count)); } ); return(sort); }
//We dont return a list of a list? //Unlike other Gets, we only care about the best case scenario public static IList <IList <T> > GetXOfAKind <T>(this IGambleCardHand <T> self, int x) where T : IGambleCard { Dictionary <GambleCardFace, IList <T> > myOccurences = self.GetValueOccurenceList(); List <IList <T> > myListOfKinds = new List <IList <T> >(); if (!self.HasXOfAKind(x)) { return(new List <IList <T> >()); } for (int i = 13; i > 0; i--) { GambleCardFace val = GambleCardExtended.CalculateGambleCardValue(i); IList <T> tempOccurenceList = myOccurences[val]; int occurences = tempOccurenceList.Count; if (occurences >= x) { for (int j = 0; j < occurences; j++) { List <T> myList = new List <T>(); for (int k = j; k < x + j && k < occurences; k++) { myList.Add(tempOccurenceList[k]); } if (myList.Count >= x) { myList.Sort( delegate(T a, T b) { return(a.CompareTo(b)); } ); myListOfKinds.Add(myList); } } } } if (myListOfKinds.Count <= 0) { return(new List <IList <T> >()); } myListOfKinds.Sort( delegate(IList <T> a, IList <T> b) { int ret = 0; for (int i = 0; i < a.Count && i < b.Count; i++) { ret = -a[i].CompareTo(b[i]); if (ret != 0) { return(ret); } } return(-a.Count.CompareTo(b.Count)); } ); IList <IList <T> > returnList = (IList <IList <T> >)(myListOfKinds); return(returnList); }
public static IList <IList <IGambleCard> > GetXConsecutive <T>(this IGambleCardHand self) { return(((IGambleCardHand <IGambleCard>)self).GetXConsecutive()); }
public static IList <IList <T> > GetXConsecutive <T>(this IGambleCardHand <T> self) where T : IGambleCard { int x = 5; List <IList <T> > allStraights = new List <IList <T> >(); if (!self.HasXConsecutive(x)) { return(new List <IList <T> >()); } Dictionary <GambleCardFace, IList <T> > occurences = self.GetValueOccurenceList(); bool found = true; for (int i = 13 - (x - 1); i >= 0; i--) { for (int j = i + (x - 1); j >= i; j--) { if (j < 0) { found = false; break; } GambleCardFace current = GambleCardExtended.CalculateGambleCardValue(j); if (occurences[current].Count <= 0) { found = false; break; } else { found = true; } } if (found) { GambleCardFace aVal = GambleCardExtended.CalculateGambleCardValue(i + (x - 1) - 0), bVal = GambleCardExtended.CalculateGambleCardValue(i + (x - 1) - 1), cVal = GambleCardExtended.CalculateGambleCardValue(i + (x - 1) - 2), dVal = GambleCardExtended.CalculateGambleCardValue(i + (x - 1) - 3), eVal = GambleCardExtended.CalculateGambleCardValue(i + (x - 1) - 4); for (int a = 0; a < occurences[aVal].Count; a++) { for (int b = 0; b < occurences[bVal].Count; b++) { for (int c = 0; c < occurences[cVal].Count; c++) { for (int d = 0; d < occurences[dVal].Count; d++) { for (int e = 0; e < occurences[eVal].Count; e++) { List <T> temp = new List <T>(); temp.Add(occurences[aVal][a]); temp.Add(occurences[bVal][b]); temp.Add(occurences[cVal][c]); temp.Add(occurences[dVal][d]); temp.Add(occurences[eVal][e]); allStraights.Add(temp); } } } } } } } //We dont need to sort since we start at ACE, go to King, and then loop back down to ACE //(We skip the last ace since we cant start with an Low-Ace, (we can with a High-Ace), because Low-Ace is the lowest card //Cant do an implicit conversion, and explicit didn't work last time i checked, but this does :D IList <IList <T> > ret = (IList <IList <T> >)(allStraights); return(ret); }
public static bool HasXConsecutive <T>(this IGambleCardHand <T> self, int x) where T : IGambleCard { return(((IGambleCardHand <IGambleCard>)self).HasXConsecutive(x)); }
public static IList <IList <T> > GetXOfSuit <T>(this IGambleCardHand <T> self) where T : IGambleCard { int x = 5; List <IList <T> > allFlushs = new List <IList <T> >(); if (!self.HasXOfSuit(x)) { return(new List <IList <T> >()); } Dictionary <GambleCardSuit, IList <T> > occurences = self.GetSuitOccurenceList(); foreach (GambleCardSuit suit in SUITS) { int count = occurences[suit].Count; if (count < x) { continue; } for (int i = 0; i < count; i++) { for (int j = i + 1; j < count; j++) { for (int k = j + 1; k < count; k++) { for (int l = k + 1; l < count; l++) { for (int m = l + 1; m < count; m++) { List <T> temp = new List <T>(); temp.Add(occurences[suit][i]); temp.Add(occurences[suit][j]); temp.Add(occurences[suit][k]); temp.Add(occurences[suit][l]); temp.Add(occurences[suit][m]); temp.Sort( delegate(T xCard, T yCard) { return(-xCard.CompareTo(yCard)); } ); allFlushs.Add(temp); } } } } } } //We dont need to sort since we start at ACE, go to King, and then loop back down to ACE //(We skip the last ace since we cant start with an Low-Ace, (we can with a High-Ace), because Low-Ace is the lowest card //Cant do an implicit conversion, and explicit didn't work last time i checked, but this does :D IList <IList <T> > ret = new List <IList <T> >(allFlushs); return(ret); }
public static Dictionary <GambleCardSuit, IList <IGambleCard> > GetSuitOccurenceList(this IGambleCardHand self) { return(((IGambleCardHand <IGambleCard>)self).GetSuitOccurenceList()); }
public static Dictionary <GambleCardSuit, int> GetSuitOccurenceCount(this IGambleCardHand self) { return(((IGambleCardHand <IGambleCard>)self).GetSuitOccurenceCount()); }
public static bool HasXOfAKind <T>(this IGambleCardHand <T> self, int x) where T : IGambleCard { return(((IGambleCardHand <IGambleCard>)self).HasXOfAKind(x)); }
public static IList <IList <IGambleCard> > GetXOfSuit(this IGambleCardHand self) { return(((IGambleCardHand <IGambleCard>)self).GetXOfSuit()); }
/* * //TODO Recursion is required for this (to have X nested loops), so for now, we brute code GetStraight<T> * //Unfortunately, in the occurence of a straight or * public static IList<IList<T>> GetXConsecutive<T>(this IList<T> self, int x) where T : IGambleCard * { * List<List<T>> * allStraights = new List<List<T>>(); * if (!self.HasXConsecutive(x)) * { * return new List<IList<T>>(); * } * * Dictionary<GambleCardValue, IList<T>> * occurences = self.GetValueOccurenceList(); * * bool found = true; * for (int i = 13 - (x-1); i >= 0; i--) * { * for (int j = i + (x-1); j >= i ; j--) * { * if (j < 0) * { * found = false; * break; * } * GambleCardValue current = GambleCardExtended.CalculateGambleCardValue(j); * if (occurences[current].Count <= 0) * { * found = false; * break; * } * else * { * found = true; * } * } * if (found) * { * } * } * //We dont need to sort since we start at ACE, go to King, and then loop back down to ACE * //(We skip the last ace since we cant start with an Low-Ace, (we can with a High-Ace), because Low-Ace is the lowest card * * //Cant do an implicit conversion, and explicit didn't work last time i checked, but this does :D * IList<IList<T>> ret = new List<IList<T>>(allStraights); * return ret; * } */ //Generic Gets public static IGambleCard GetHighCard(this IGambleCardHand self) { return(((IGambleCardHand <IGambleCard>)self).GetHighCard()); }
//We dont return a list of a list? //Unlike other Gets, we only care about the best case scenario public static IList <IList <IGambleCard> > GetXOfAKind(this IGambleCardHand self, int x) { return(((IGambleCardHand <IGambleCard>)self).GetXOfAKind(x)); }