Esempio n. 1
0
        public static PokerCard IsThreeOfKind(PokerHand hand, PokerCard[] CommCards)
        {
            PokerCard retTripple = new PokerCard(PokerCard.Cards.Undefined, PokerCard.Suits.Hearts);
            var       allCards   = CreateSortedList(hand, CommCards);

            int       counter  = 0;
            PokerCard prevCard = new PokerCard(PokerCard.Cards.Undefined, PokerCard.Suits.Hearts);

            foreach (PokerCard card in allCards)
            {
                if (prevCard.Card == PokerCard.Cards.Undefined || prevCard.Card == card.Card)
                {
                    counter++;
                }
                else
                {
                    counter = 0;
                }
                prevCard = card;

                if (counter == 3)
                {
                    retTripple = prevCard;
                    break;
                }
            }

            return(retTripple);
        }
Esempio n. 2
0
        public static Tuple <PokerCard, PokerCard> IsTwoPairs(PokerHand hand, PokerCard[] CommCards)
        {
            PokerCard retPair1 = new PokerCard(PokerCard.Cards.Undefined, PokerCard.Suits.Hearts);
            PokerCard retPair2 = new PokerCard(PokerCard.Cards.Undefined, PokerCard.Suits.Hearts);

            foreach (PokerCard commCard in CommCards)
            {
                if (commCard.Card == hand.MyCards[0].Card)
                {
                    retPair1 = commCard;
                }
            }

            if (retPair1.Card != PokerCard.Cards.Undefined)
            {
                foreach (PokerCard commCard in CommCards)
                {
                    if (commCard.Card == hand.MyCards[1].Card)
                    {
                        retPair2 = commCard;
                    }
                }
            }

            return(new Tuple <PokerCard, PokerCard>(retPair1, retPair2));
        }
Esempio n. 3
0
        public static PokerCard IsFlush(PokerHand hand, PokerCard[] CommCards)
        {
            PokerCard retTopCard = new PokerCard(PokerCard.Cards.Undefined, PokerCard.Suits.Hearts);
            var       allCards   = CreateSortedList(hand, CommCards);

            List <PokerCard> countSpades   = new List <PokerCard>();
            List <PokerCard> countHearts   = new List <PokerCard>();
            List <PokerCard> countDiamonds = new List <PokerCard>();
            List <PokerCard> countClubs    = new List <PokerCard>();

            foreach (PokerCard card in allCards)
            {
                switch (card.Suit)
                {
                case PokerCard.Suits.Spades:
                    countSpades.Add(card);
                    break;

                case PokerCard.Suits.Hearts:
                    countHearts.Add(card);
                    break;

                case PokerCard.Suits.Diamonds:
                    countDiamonds.Add(card);
                    break;

                case PokerCard.Suits.Clubs:
                    countClubs.Add(card);
                    break;
                }
            }

            if (countSpades.Count >= 5)
            {
                retTopCard = countSpades[0];
            }
            else if (countHearts.Count >= 5)
            {
                retTopCard = countHearts[0];
            }
            else if (countDiamonds.Count >= 5)
            {
                retTopCard = countDiamonds[0];
            }
            else if (countClubs.Count >= 5)
            {
                retTopCard = countClubs[0];
            }

            return(retTopCard);
        }
Esempio n. 4
0
        public static PokerCard IsPair(PokerHand hand, PokerCard[] CommCards)
        {
            PokerCard retPair = new PokerCard(PokerCard.Cards.Undefined, PokerCard.Suits.Hearts);

            if (hand.MyCards[0].Card == hand.MyCards[1].Card)
            {
                retPair = hand.MyCards[0];
            }

            foreach (PokerCard commCard in CommCards)
            {
                if ((commCard.Card == hand.MyCards[0].Card || commCard.Card == hand.MyCards[1].Card) &&
                    commCard.Card > retPair.Card)
                {
                    retPair = commCard;
                }
            }

            return(retPair);
        }
Esempio n. 5
0
        public static PokerCard IsStraight(PokerHand hand, PokerCard[] CommCards)
        {
            PokerCard retTopCard = new PokerCard(PokerCard.Cards.Undefined, PokerCard.Suits.Hearts);
            var       allCards   = CreateSortedList(hand, CommCards);

            bool      lowAceCase = false;
            int       counter    = 0;
            PokerCard prevCard   = new PokerCard(PokerCard.Cards.Undefined, PokerCard.Suits.Hearts);

            foreach (PokerCard card in allCards)
            {
                if (prevCard.Card == PokerCard.Cards.Undefined)
                {
                    counter++;
                }
                else if (prevCard.Card == card.Card || (int)prevCard.Card == (int)card.Card + 1)
                {
                    counter++;

                    if (card.Card == PokerCard.Cards.Two && allCards[0].Card == PokerCard.Cards.Ace && counter != 5)
                    {
                        lowAceCase = true;
                        counter++;
                    }
                }
                else
                {
                    counter = 1;
                }
                prevCard = card;

                if (counter == 5)
                {
                    retTopCard = allCards[allCards.IndexOf(card) - (lowAceCase ? 3 : 4)];
                    break;
                }
            }

            return(retTopCard);
        }