public static IList <T> GetPair <T>(this ITexasHoldemPokerHand <T> self) where T : IGambleCard { List <IList <T> > pairs = new List <IList <T> >(self.GetXOfAKind(2)); if (pairs.Count <= 0) { return(new List <T>()); } pairs.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)); } ); return(pairs[0]); }
public static IList <T> GetStraight <T>(this ITexasHoldemPokerHand <T> self) where T : IGambleCard { IList <IList <T> > straights = self.GetXConsecutive(); if (straights.Count <= 0) { return(new List <T>()); } List <IList <T> > sort = new List <IList <T> >(straights); 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[0]); }
public static IList <T> GetTwoPair <T>(this ITexasHoldemPokerHand <T> self) where T : IGambleCard { ITexasHoldemPokerHand <T> tempHand = new TexasHoldemPokerHand <T>(self); IList <T> pair = new List <T>(), tempPair = tempHand.GetPair(); if (tempPair.Count > 0) { for (int i = 0; i < tempPair.Count; i++) { tempHand.Remove(tempPair[i]); pair.Add(tempPair[i]); } tempPair = tempHand.GetPair(); if (tempPair.Count > 0) { for (int i = 0; i < tempPair.Count; i++) { //We dont carea bout removing, so just add pair.Add(tempPair[i]); } } else { pair.Clear(); } } return(pair); }
public static IList <T> GetStraightFlush <T>(this ITexasHoldemPokerHand <T> self) where T : IGambleCard { List <IList <T> > allStraightFlushs = new List <IList <T> >(self.GetXConsecutiveOfSuit()); if (allStraightFlushs.Count <= 0) { return(new List <T>()); } allStraightFlushs.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(allStraightFlushs[0]); }
//Get Explicit Amounts public static IList <T> GetFullHouse <T>(this ITexasHoldemPokerHand <T> self) where T : IGambleCard { ITexasHoldemPokerHand <T> tempHand = new TexasHoldemPokerHand <T>(self); IList <T> fullHouse = new List <T>(), tempKind = tempHand.GetThreeOfAKind(); if (tempKind.Count > 0) { for (int i = 0; i < tempKind.Count; i++) { tempHand.Remove(tempKind[i]); fullHouse.Add(tempKind[i]); } tempKind = tempHand.GetPair(); if (tempKind.Count > 0) { for (int i = 0; i < tempKind.Count; i++) { //We dont carea bout removing, so just add fullHouse.Add(tempKind[i]); } } else { fullHouse.Clear(); } } return(fullHouse); }
public static ITexasHoldemPokerHand GetBestPokerHand(this ITexasHoldemPokerHand self) { ITexasHoldemPokerHand <IGambleCard> temp = ((ITexasHoldemPokerHand <IGambleCard>)self); ITexasHoldemPokerHand <IGambleCard> best = temp.GetBestPokerHand(); return(new TexasHoldemPokerHand(best, best.Rank)); }
public static IList <T> GetRoyalFlush <T>(this ITexasHoldemPokerHand <T> self) where T : IGambleCard { IList <T> straightFlush = self.GetStraightFlush(); if (straightFlush.Count <= 0 || straightFlush[0].Face != GambleCardFace.Ace) { return(new List <T>()); } return(straightFlush); }
public TexasHoldemPokerHand(ITexasHoldemPokerHand hand) : base(hand) { }
public TexasHoldemPokerHand(ITexasHoldemPokerHand <T> hand) : this(hand, hand.Rank) { }
public static ITexasHoldemPokerHand <T> GetBestPokerHand <T>(this ITexasHoldemPokerHand <T> self) where T : IGambleCard { ITexasHoldemPokerHand <T> tempHand = new TexasHoldemPokerHand <T>(self), currentBest = new TexasHoldemPokerHand <T>(); IList <T> tempBest; TexasHoldemPokerRank currentRank = TexasHoldemPokerRank.HighCard; bool hit = false; int remaining = (5 - currentBest.Count); tempBest = tempHand.GetRoyalFlush(); if (tempBest.Count > 0 && !hit) { if (currentRank < TexasHoldemPokerRank.RoyalFlush) { currentRank = TexasHoldemPokerRank.RoyalFlush; } for (int i = 0; i < tempBest.Count; i++) { currentBest.Add(tempBest[i]); tempHand.Remove(tempBest[i]); } remaining = (5 - currentBest.Count); hit = true; } if (!hit) { tempBest = tempHand.GetStraightFlush(); if (tempBest.Count > 0) { if (currentRank < TexasHoldemPokerRank.StraightFlush) { currentRank = TexasHoldemPokerRank.StraightFlush; } for (int i = 0; i < tempBest.Count; i++) { currentBest.Add(tempBest[i]); tempHand.Remove(tempBest[i]); } remaining = (5 - currentBest.Count); hit = true; } } if (!hit) { tempBest = tempHand.GetFourOfAKind(); if (tempBest.Count > 0) { if (currentRank < TexasHoldemPokerRank.FourOfAKind) { currentRank = TexasHoldemPokerRank.FourOfAKind; } for (int i = 0; i < tempBest.Count; i++) { currentBest.Add(tempBest[i]); tempHand.Remove(tempBest[i]); } remaining = (5 - currentBest.Count); hit = true; } } if (!hit) { tempBest = tempHand.GetFullHouse(); if (tempBest.Count > 0) { if (currentRank < TexasHoldemPokerRank.FullHouse) { currentRank = TexasHoldemPokerRank.FullHouse; } for (int i = 0; i < tempBest.Count; i++) { currentBest.Add(tempBest[i]); tempHand.Remove(tempBest[i]); } remaining = (5 - currentBest.Count); hit = true; } } if (!hit) { tempBest = tempHand.GetFlush(); if (tempBest.Count > 0) { if (currentRank < TexasHoldemPokerRank.Flush) { currentRank = TexasHoldemPokerRank.Flush; } for (int i = 0; i < tempBest.Count; i++) { currentBest.Add(tempBest[i]); tempHand.Remove(tempBest[i]); } remaining = (5 - currentBest.Count); hit = true; } } if (!hit) { tempBest = tempHand.GetStraight(); if (tempBest.Count > 0) { if (currentRank < TexasHoldemPokerRank.Straight) { currentRank = TexasHoldemPokerRank.Straight; } for (int i = 0; i < tempBest.Count; i++) { currentBest.Add(tempBest[i]); tempHand.Remove(tempBest[i]); } remaining = (5 - currentBest.Count); hit = true; } } if (!hit) { tempBest = tempHand.GetThreeOfAKind(); if (tempBest.Count > 0) { if (currentRank < TexasHoldemPokerRank.ThreeOfAKind) { currentRank = TexasHoldemPokerRank.ThreeOfAKind; } for (int i = 0; i < tempBest.Count; i++) { currentBest.Add(tempBest[i]); tempHand.Remove(tempBest[i]); } remaining = (5 - currentBest.Count); hit = true; } } if (!hit) { tempBest = tempHand.GetTwoPair(); if (tempBest.Count > 0) { if (currentRank < TexasHoldemPokerRank.TwoPair) { currentRank = TexasHoldemPokerRank.TwoPair; } for (int i = 0; i < tempBest.Count; i++) { currentBest.Add(tempBest[i]); tempHand.Remove(tempBest[i]); } remaining = (5 - currentBest.Count); hit = true; } } if (!hit) { tempBest = tempHand.GetPair(); if (tempBest.Count > 0) { if (currentRank < TexasHoldemPokerRank.OnePair) { currentRank = TexasHoldemPokerRank.OnePair; } for (int i = 0; i < tempBest.Count; i++) { currentBest.Add(tempBest[i]); tempHand.Remove(tempBest[i]); } remaining = (5 - currentBest.Count); hit = true; } } while (remaining >= 1) { T card = tempHand.GetHighCard(); if (card != null) { currentBest.Add(card); tempHand.Remove(card); remaining = (5 - currentBest.Count); } else { break; } } //Console.WriteLine(currentRank.ToString()); currentBest.Rank = currentRank; return(currentBest); }
public static IList <IGambleCard> GetPair(this ITexasHoldemPokerHand self) { return(((ITexasHoldemPokerHand <IGambleCard>)self).GetPair()); }
public static IList <IGambleCard> GetThreeOfAKind(this ITexasHoldemPokerHand self) { return(((ITexasHoldemPokerHand <IGambleCard>)self).GetThreeOfAKind()); }
public static IList <IGambleCard> GetStraightFlush(this ITexasHoldemPokerHand self) { return(((ITexasHoldemPokerHand <IGambleCard>)self).GetStraightFlush()); }