Exemplo n.º 1
0
 public TexasHoldemPokerHand(IHand <IGambleCard> hand, TexasHoldemPokerRank rank = TexasHoldemPokerRank.HighCard)
     : base(hand, rank)
 {
     this.Rank = rank;
 }
Exemplo n.º 2
0
 public TexasHoldemPokerHand(TexasHoldemPokerRank rank = TexasHoldemPokerRank.HighCard, params IGambleCard[] cards)
     : base(rank, cards)
 {
     this.Rank = rank;
 }
Exemplo n.º 3
0
 public TexasHoldemPokerHand(TexasHoldemPokerRank rank = TexasHoldemPokerRank.HighCard, params T[] cards)
     : base(cards)
 {
     this.Rank = rank;
 }
Exemplo n.º 4
0
 public TexasHoldemPokerHand(IHand <T> hand, TexasHoldemPokerRank rank = TexasHoldemPokerRank.HighCard)
     : base(hand)
 {
     this.Rank = 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);
        }