当前位置: 首页>>代码示例>>C#>>正文


C# Hand.Count方法代码示例

本文整理汇总了C#中Hand.Count方法的典型用法代码示例。如果您正苦于以下问题:C# Hand.Count方法的具体用法?C# Hand.Count怎么用?C# Hand.Count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Hand的用法示例。


在下文中一共展示了Hand.Count方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: getBestHandEfficiently

 //get best class without running isRoyalFlush, since straightflush covers the royal flush
 public static Hand getBestHandEfficiently(Hand hand)
 {
     if (hand.Count() < 5)
     {
         hand.Clear();
         return hand;
     }
     if (isStraightFlush(hand))
         return getStraightFlush(hand);
     if (isFourOfAKind(hand))
         return getFourOfAKind(hand);
     if (isFullHouse(hand))
         return getFullHouse(hand);
     if (isFlush(hand))
         return getFlush(hand);
     if (isStraight(hand))
         return getStraight(hand);
     if (isThreeOfAKind(hand))
         return getThreeOfAKind(hand);
     if (isTwoPair(hand))
         return getTwoPair(hand);
     if (isOnePair(hand))
         return getOnePair(hand);
     return getHighCard(hand);
 }
开发者ID:Rodbourn,项目名称:TexasHoldem,代码行数:26,代码来源:HandCombination.cs

示例2: isStraightFlush

        //use recursion to get rid of pairs, then evaluate straight flush
        public static bool isStraightFlush(Hand hand)
        {
            hand.sortByRank();
            Hand simplifiedhand1, simplifiedhand2; //to be set the same as hand - cards are removed from this hand to evaluate straights separately without the interference of pairs or three-of-a-kind
            for (int i = 0; i <= hand.Count() - 2; i++)
            {
                if (hand.getCard(i) == hand.getCard(i + 1))
                {
                    simplifiedhand1 = new Hand(hand);
                    simplifiedhand1.Remove(i);
                    simplifiedhand2 = new Hand(hand);
                    simplifiedhand2.Remove(i + 1);
                    if (HandCombination.isStraightFlush(simplifiedhand1))
                        return true;
                    if (HandCombination.isStraightFlush(simplifiedhand2))
                        return true;
                }
            }
            for (int i = 0; i <= hand.Count() - 5; i++)
            {
                int currentrank = hand.getCard(i).getRank(), currentsuit = hand.getCard(i).getSuit();
                if (currentrank == hand.getCard(i + 1).getRank() + 1 && currentrank == hand.getCard(i + 2).getRank() + 2 && currentrank == hand.getCard(i + 3).getRank() + 3 && currentrank == hand.getCard(i + 4).getRank() + 4 && currentsuit == hand.getCard(i + 1).getSuit() && currentsuit == hand.getCard(i + 2).getSuit() && currentsuit == hand.getCard(i + 3).getSuit() && currentsuit == hand.getCard(i + 4).getSuit())
                    return true;

            }
            for (int i = 0; i <= hand.Count() - 4; i++)
            {
                int currentrank = hand.getCard(i).getRank(), currentsuit = hand.getCard(i).getSuit();
                if (currentrank == 5 && hand.getCard(i + 1).getRank() == 4 && hand.getCard(i + 2).getRank() == 3 && hand.getCard(i + 3).getRank() == 2 && hand.getCard(0).getRank() == 14 && currentsuit == hand.getCard(i + 1).getSuit() && currentsuit == hand.getCard(i + 2).getSuit() && currentsuit == hand.getCard(i + 3).getSuit() && currentsuit == hand.getCard(0).getSuit())
                    return true;
            }
            return false;
        }
开发者ID:Rodbourn,项目名称:TexasHoldem,代码行数:34,代码来源:HandCombination.cs

示例3: isStraight

 //explanation below
 public static bool isStraight(Hand hand)
 {
     hand.sortByRank();
     if(hand.getCard(0).getRank()==14)
         hand.Add(new Card((int)RANK.ACE,hand.getCard(0).getSuit()));
     int straightCount=1;
     for (int i = 0; i <= hand.Count() - 2; i++)
     {
         //if 5 cards are found to be straights, break out of the loop
         if (straightCount == 5)
             break;
         int currentrank = hand.getCard(i).getRank();
         //if cards suit differ by 1, increment straight
         if (currentrank - hand.getCard(i + 1).getRank() == 1)
             straightCount++;
         //specific condition for 2-A
         else if (currentrank == 2 && hand.getCard(i + 1).getRank() == 14)
             straightCount++;
         //if cards suit differ by more than 1, reset straight to 1
         else if (currentrank - hand.getCard(i + 1).getRank() > 1)
             straightCount = 1;
         //if card suits does not differ, do nothing
     }
     if (hand.getCard(0).getRank() == 14)
         hand.Remove(hand.Count() - 1);
     //depending on the straight count, return true or false
     if (straightCount == 5)
         return true;
     return false;
 }
开发者ID:Rodbourn,项目名称:TexasHoldem,代码行数:31,代码来源:HandCombination.cs

示例4: isRoyalFlush

 //look for royal flush, removing pair using recursion
 public static bool isRoyalFlush(Hand hand)
 {
     hand.sortByRank();
     Hand simplifiedhand1, simplifiedhand2; //to be set the same as hand - cards are removed from this hand to evaluate straights separately without the interference of pairs or three-of-a-kind
     for (int i = 0; i <= hand.Count() - 2; i++)
     {
         if (hand[i] == hand[i+1])
         {
             simplifiedhand1 = new Hand(hand);
             simplifiedhand1.Remove(i);
             simplifiedhand2 = new Hand(hand);
             simplifiedhand2.Remove(i + 1);
             if (HandCombination.isRoyalFlush(simplifiedhand1))
                 return true;
             if (HandCombination.isRoyalFlush(simplifiedhand2))
                 return true;
         }
     }
     int currentsuit = hand.getCard(0).getSuit();
     if (hand.getCard(0).getRank() == 14 && hand.getCard(1).getRank() == 13 && hand.getCard(2).getRank() == 12 && hand.getCard(3).getRank() == 11 && hand.getCard(4).getRank() == 10 && hand.getCard(1).getSuit() == currentsuit && hand.getCard(2).getSuit() == currentsuit && hand.getCard(3).getSuit() == currentsuit && hand.getCard(4).getSuit() == currentsuit)
         return true;
     else
         return false;
 }
开发者ID:Rodbourn,项目名称:TexasHoldem,代码行数:25,代码来源:HandCombination.cs

示例5: isOnePair

 public static bool isOnePair(Hand hand)
 {
     hand.sortByRank();
     for (int i = 0; i <= hand.Count() - 2; i++)
     {
         if (hand.getCard(i) == hand.getCard(i + 1))
             return true;
     }
     return false;
 }
开发者ID:Rodbourn,项目名称:TexasHoldem,代码行数:10,代码来源:HandCombination.cs

示例6: CalculateHandValueHard

        //determine the hole cards of the player and the community cards to be dealt
        //determines who will win the showdown at the end
        public void CalculateHandValueHard(Hand otherHand,Deck deck)
        {
            Hand knownCommunityCards = new Hand();
            Hand remainingCommunityCards = new Hand();
            //add known community cards
            for (int i = 2; i < myHand.Count(); i++)
            {
                knownCommunityCards.Add(myHand[i]);
            }
            //generate remaining community cards
            if (knownCommunityCards.Count() < 5)
            {
                remainingCommunityCards.Add(deck.Deal());
                if (knownCommunityCards.Count() < 4)
                {
                    remainingCommunityCards.Add(deck.Deal());
                    if (knownCommunityCards.Count() < 3)
                    {
                        remainingCommunityCards.Add(deck.Deal());
                        remainingCommunityCards.Add(deck.Deal());
                        remainingCommunityCards.Add(deck.Deal());
                    }
                }
            }
            //add the remaining cards
            this.AddToHand(remainingCommunityCards);
            otherHand += remainingCommunityCards;
            otherHand += knownCommunityCards;

            //compare hands
            if (HandCombination.getBestHandEfficiently(new Hand(myHand)) > HandCombination.getBestHandEfficiently(new Hand(otherHand)))
                handValue = 1;
            else if (HandCombination.getBestHandEfficiently(new Hand(myHand)) < HandCombination.getBestHandEfficiently(new Hand(otherHand)))
                handValue = 0;
            else
                handValue = 0.5;
            for (int i = 0; i < remainingCommunityCards.Count(); i++)
            {
                myHand.Remove(remainingCommunityCards[i]);
            }
        }
开发者ID:Rodbourn,项目名称:TexasHoldem,代码行数:43,代码来源:AIPlayer.cs

示例7: button21_Click

 private void button21_Click(object sender, EventArgs e)
 {
     Hand handhighlights = new Hand();
     handhighlights = HandCombination.getOnePair(new Hand(myHand1));
     for (int i = 0; i < myHand1.Count(); i++)
     {
         for (int j = 0; j < handhighlights.Count(); j++)
         {
             if (handhighlights.getCard(j) == myHand1.getCard(i) && handhighlights.getCard(j).getSuit() == myHand1.getCard(i).getSuit())
             {
                 myHand1.getCard(i).Highlight();
             }
         }
     }
     int x = 0;
     for (int i = 0; i < myHand1.Count(); i++)
     {
         Bitmap bitmap = new Bitmap(myHand1.getCard(i).getImage());
         Graphics g = Graphics.FromImage(b2);
         g.DrawImage(bitmap, 5 + x * 75, 5, 71, 96);
         x++;
     }
     pictureBox1.Image = b2;
 }
开发者ID:Rodbourn,项目名称:TexasHoldem,代码行数:24,代码来源:Form1.cs

示例8: getKickers

 //get all remaining cards, if necessary, to form 5 cards
 private static Hand getKickers(Hand hand, Hand specialCards)
 {
     if (specialCards.Count() == 0)
         return specialCards;
     for (int i = 0; i < specialCards.Count(); i++)
     {
         hand.Remove(specialCards.getCard(i));
     }
     for (int i = 0; i < hand.Count();i++)
     {
         if (specialCards.Count() >= 5)
             break;
         specialCards.Add(hand.getCard(i));
         specialCards.setValue(hand.getCard(i).getRank());
     }
     return specialCards;
 }
开发者ID:Rodbourn,项目名称:TexasHoldem,代码行数:18,代码来源:HandCombination.cs

示例9: getTwoPair

 public static Hand getTwoPair(Hand hand)
 {
     hand.sortByRank();
     Hand twopair = new Hand();
     twopair.setValue(3);
     int pairCount = 0;
     for (int i = 0; i <= hand.Count() - 2; i++)
     {
         if (hand.getCard(i) == hand.getCard(i + 1))
         {
             twopair.setValue(hand.getCard(i).getRank());
             twopair.Add(hand.getCard(i));
             twopair.Add(hand.getCard(i+1));
             pairCount++;
             if (pairCount == 2)
                 break;
             i++; //the pair has already been checked, i must be incremented an additional time to avoid using a card in this pair again. This prevents the program from identifying 3 of a kind as 2 pairs.
         }
     }
     if (pairCount == 2)
         return getKickers(hand,twopair);
     else
         twopair.Clear();
         return twopair;
 }
开发者ID:Rodbourn,项目名称:TexasHoldem,代码行数:25,代码来源:HandCombination.cs

示例10: getThreeOfAKind

 public static Hand getThreeOfAKind(Hand hand)
 {
     hand.sortByRank();
     Hand threeofakind = new Hand();
     threeofakind.setValue(4);
     for (int i = 0; i <= hand.Count() - 3; i++)
     {
         if (hand.getCard(i) == hand.getCard(i + 1) && hand.getCard(i) == hand.getCard(i + 2))
         {
             threeofakind.setValue(hand.getCard(i).getRank());
             threeofakind.Add(hand.getCard(i));
             threeofakind.Add(hand.getCard(i + 1));
             threeofakind.Add(hand.getCard(i + 2));
             break;
         }
     }
     return getKickers(hand, threeofakind);
 }
开发者ID:Rodbourn,项目名称:TexasHoldem,代码行数:18,代码来源:HandCombination.cs

示例11: getStraightFlush

 //get straight flush using two pointer variable and taking care of all cases
 public static Hand getStraightFlush(Hand hand)
 {
     hand.sortByRank();
     Hand straightflush = new Hand();
     straightflush.setValue(9);
     if (hand.getCard(0).getRank() == 14)
         hand.Add(new Card((int)RANK.ACE, hand.getCard(0).getSuit()));
     //int straightflushCount = 1;
     straightflush.Add(hand.getCard(0));
     int ptr1=0, ptr2=1;
     while (ptr1 < hand.Count() - 2 || ptr2 < hand.Count())
     {
         if (straightflush.Count() >= 5)
             break;
         int rank1=hand.getCard(ptr1).getRank(), rank2=hand.getCard(ptr2).getRank();
         int suit1=hand.getCard(ptr1).getSuit(), suit2=hand.getCard(ptr2).getSuit();
         if (rank1 - rank2 == 1 && suit1 == suit2)
         {
             straightflush.Add(hand.getCard(ptr2));
             ptr1 = ptr2;
             ptr2++;
         }
         else if(rank1==2&&rank2==14&&suit1==suit2)
         {
             straightflush.Add(hand.getCard(ptr2));
             ptr1 = ptr2;
             ptr2++;
         }
         else
         {
             if (rank1 - rank2 <= 1)
                 ptr2++;
             else
             {
                 straightflush.Clear();
                 straightflush.setValue(9);
                 ptr1++;
                 ptr2=ptr1+1;
                 straightflush.Add(hand.getCard(ptr1));
             }
         }
     }
     if (hand.getCard(0).getRank() == 14)
         hand.Remove(hand.Count() - 1);
     straightflush.setValue(straightflush.getCard(0).getRank());
     if (straightflush.Count() < 5)
         straightflush.Clear();
     return straightflush;
 }
开发者ID:Rodbourn,项目名称:TexasHoldem,代码行数:50,代码来源:HandCombination.cs

示例12: getOnePair

 public static Hand getOnePair(Hand hand)
 {
     hand.sortByRank();
     Hand onepair = new Hand();
     onepair.setValue(2);
     for (int i = 0; i <= hand.Count() - 2; i++)
     {
         if (hand.getCard(i) == hand.getCard(i + 1))
         {
             onepair.setValue(hand.getCard(i).getRank());
             onepair.Add(hand.getCard(i));
             onepair.Add(hand.getCard(i + 1));
             break;
         }
     }
     return getKickers(hand, onepair);
 }
开发者ID:Rodbourn,项目名称:TexasHoldem,代码行数:17,代码来源:HandCombination.cs

示例13: getFullHouse

 public static Hand getFullHouse(Hand hand)
 {
     hand.sortByRank();
     Hand fullhouse = new Hand();
     fullhouse.setValue(7);
     bool threeofakind = false, pair = false;
     int threeofakindRank = 0;
     for (int i = 0; i <= hand.Count() - 3; i++)
     {
         if (hand.getCard(i) == hand.getCard(i + 1) && hand.getCard(i) == hand.getCard(i + 2))
         {
             threeofakind = true;
             threeofakindRank = hand.getCard(i).getRank();
             fullhouse.Add(hand.getCard(i));
             fullhouse.Add(hand.getCard(i + 1));
             fullhouse.Add(hand.getCard(i + 2));
             fullhouse.setValue(hand.getCard(i).getRank());
             break;
         }
     }
     for (int i = 0; i <= hand.Count() - 2; i++)
     {
         if (hand.getCard(i) == hand.getCard(i + 1) && hand.getCard(i).getRank() != threeofakindRank)
         {
             pair = true;
             fullhouse.Add(hand.getCard(i));
             fullhouse.Add(hand.getCard(i + 1));
             fullhouse.setValue(hand.getCard(i).getRank());
             break;
         }
     }
     if (threeofakind == true && pair == true)
         return fullhouse;
     else
     {
         fullhouse.Clear();
         return fullhouse;
     }
 }
开发者ID:Rodbourn,项目名称:TexasHoldem,代码行数:39,代码来源:HandCombination.cs

示例14: getFourOfAKind

 //same as above except return the cards themselves
 public static Hand getFourOfAKind(Hand hand)
 {
     Hand fourofakind = new Hand();
     fourofakind.setValue(8);
     hand.sortByRank();
     for (int i = 0; i <= hand.Count() - 4; i++)
     {
         if (hand.getCard(i) == hand.getCard(i + 1) && hand.getCard(i) == hand.getCard(i + 2) && hand.getCard(i) == hand.getCard(i + 3))
         {
             fourofakind.Add(hand.getCard(i));
             fourofakind.Add(hand.getCard(i + 1));
             fourofakind.Add(hand.getCard(i + 2));
             fourofakind.Add(hand.getCard(i + 3));
             fourofakind.setValue(hand.getCard(i).getRank());
             break;
         }
     }
     return getKickers(hand,fourofakind);
 }
开发者ID:Rodbourn,项目名称:TexasHoldem,代码行数:20,代码来源:HandCombination.cs

示例15: isThreeOfAKind

 public static bool isThreeOfAKind(Hand hand)
 {
     hand.sortByRank();
     for (int i = 0; i <= hand.Count() - 3; i++)
     {
         if (hand.getCard(i) == hand.getCard(i + 1) && hand.getCard(i) == hand.getCard(i + 2))
             return true;
     }
     return false;
 }
开发者ID:Rodbourn,项目名称:TexasHoldem,代码行数:10,代码来源:HandCombination.cs


注:本文中的Hand.Count方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。