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


C# Poker.Hand类代码示例

本文整理汇总了C#中Poker.Hand的典型用法代码示例。如果您正苦于以下问题:C# Hand类的具体用法?C# Hand怎么用?C# Hand使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: Catagorize

        public override HandRanking Catagorize(Hand hand)
        {
            Dictionary<Value, int> seen = new Dictionary<Value, int>();

            foreach (Card c in hand.Cards)
            {
                if (seen.ContainsKey(c.Value))
                {
                    seen[c.Value]++;
                }
                else
                {
                    seen[c.Value] = 1;
                }
            }

            if (seen.Count == 2)
            {
                if(seen.ContainsValue(3) && seen.ContainsValue(2))
                {
                    return HandRanking.FullHouse;
                }
            }

            return Next.Catagorize(hand);
        }
开发者ID:skalinets,项目名称:DesignPatterns,代码行数:26,代码来源:Catagorizers.cs

示例2: CompareHands_EqualFullHouses

        public void CompareHands_EqualFullHouses()
        {
            IList<ICard> firstHandCards = new List<ICard>
            {
                new Card(CardFace.Six, CardSuit.Diamonds),
                new Card(CardFace.Two, CardSuit.Spades),
                new Card(CardFace.Two, CardSuit.Diamonds),
                new Card(CardFace.Two, CardSuit.Hearts),
                new Card(CardFace.Six, CardSuit.Hearts),
            };

            IList<ICard> secondHandCards = new List<ICard>
            {
                new Card(CardFace.Six, CardSuit.Diamonds),
                new Card(CardFace.Two, CardSuit.Spades),
                new Card(CardFace.Two, CardSuit.Diamonds),
                new Card(CardFace.Two, CardSuit.Hearts),
                new Card(CardFace.Six, CardSuit.Hearts),
            };

            Hand firstHand = new Hand(firstHandCards);
            Hand secondHand = new Hand(secondHandCards);

            PokerHandsChecker checker = new PokerHandsChecker();

            int expected = 0;
            int actual = checker.CompareHands(firstHand, secondHand);
            Assert.AreEqual(expected, actual);
        }
开发者ID:Nottyy,项目名称:TelerikAcademy,代码行数:29,代码来源:PokerHandsCheckerTestMethodCompareHands.cs

示例3: Main

        static void Main()
        {
            Console.BackgroundColor = ConsoleColor.White;
            Console.ForegroundColor = ConsoleColor.Black;
            ICard card = new Card(CardFace.Ace, CardSuit.Clubs);
            Console.WriteLine(card);

            IHand hand = new Hand(new List<ICard>() 
            { 
                new Card(CardFace.Ace, CardSuit.Clubs),
                new Card(CardFace.Ace, CardSuit.Diamonds),
                new Card(CardFace.King, CardSuit.Hearts),
                new Card(CardFace.King, CardSuit.Spades),
                new Card(CardFace.Seven, CardSuit.Diamonds),
            });

            IHand hand2 = new Hand(new List<ICard>() 
            { 
                new Card(CardFace.Two, CardSuit.Clubs),
                new Card(CardFace.Two, CardSuit.Diamonds),
                new Card(CardFace.Three, CardSuit.Hearts),
                new Card(CardFace.Three, CardSuit.Spades),
                new Card(CardFace.Two, CardSuit.Hearts),
            });

            Console.WriteLine(hand);

            IPokerHandsChecker checker = new PokerHandsChecker();
            Console.WriteLine("Is valid hand: " + checker.IsValidHand(hand));
            Console.WriteLine("Is one pair: " + checker.IsOnePair(hand));
            Console.WriteLine("Is two pairs: " + checker.IsTwoPair(hand));

            Console.WriteLine(Environment.NewLine + "Compare hands. 1 for first hand. -1 for second hand. 0 for same hands");
            Console.WriteLine("Hand: {0}, Hand2: {1} Compare: {2}", hand, hand2, checker.CompareHands(hand, hand2));
        }
开发者ID:VyaraGGeorgieva,项目名称:TelerikAcademy,代码行数:35,代码来源:PokerExample.cs

示例4: Main

        internal static void Main()
        {
            ICard card = new Card(CardFace.Ace, CardSuit.Clubs);
            Console.WriteLine(card);

            IHand hand = new Hand(new List<ICard>()
            {
                new Card(CardFace.Ace, CardSuit.Clubs),
                new Card(CardFace.Ace, CardSuit.Diamonds),
                new Card(CardFace.King, CardSuit.Hearts),
                new Card(CardFace.King, CardSuit.Spades),
                new Card(CardFace.Seven, CardSuit.Diamonds),
            });
            Console.WriteLine(hand);

            IPokerHandsChecker checker = new PokerHandsChecker();
            Console.WriteLine(checker.IsValidHand(hand));
            Console.WriteLine(checker.IsOnePair(hand));
            Console.WriteLine(checker.IsTwoPairs(hand));

            int a = 5;
            int b = 6;

            Console.WriteLine(b.CompareTo(a));
        }
开发者ID:Nottyy,项目名称:TelerikAcademy,代码行数:25,代码来源:PokerExample.cs

示例5: PokerHandsChecker_IsThreeOfAKind_ContainsLessThanThreeCardsWithSameFace_ShouldBe_False

        public void PokerHandsChecker_IsThreeOfAKind_ContainsLessThanThreeCardsWithSameFace_ShouldBe_False()
        {
            var currentHand = new Hand(cards);
            currentHand.Cards.RemoveAt(0);

            Assert.IsFalse(checker.IsThreeOfAKind(currentHand));
        }
开发者ID:VDGone,项目名称:TelerikAcademy-1,代码行数:7,代码来源:PokerHandsCheckerIsThreeOfAKindTests.cs

示例6: TestAllPossibleFourOfAKindHands

        public void TestAllPossibleFourOfAKindHands()
        {
            IList<ICard> fourOfAKindCollection = new List<ICard>();
            byte countOfAllValues = 13;
            byte countOfAllKinds = 4;
            Hand playerHand;
            List<bool> results = new List<bool>();
            int faceOfAdditionalCard;

            for (int i = 0; i < countOfAllValues; i++)
            {
                faceOfAdditionalCard = i;

                for (int j = 1; j <= countOfAllKinds; j++)
                {
                    fourOfAKindCollection.Add(new Card((CardFace)i + 2, (CardSuit)j));
                }

                if (faceOfAdditionalCard + 3 > 14)
                {
                    faceOfAdditionalCard = 2;
                }

                fourOfAKindCollection.Add(new Card((CardFace)faceOfAdditionalCard + 3, CardSuit.Hearts));
                playerHand = new Hand(fourOfAKindCollection);

                results.Add(this.checker.IsFourOfAKind(playerHand));

                fourOfAKindCollection.Clear();
            }

            byte countOfAllTrueResults = (byte)results.Count(res => res == true);

            Assert.AreEqual(results.Count, countOfAllTrueResults);
        }
开发者ID:viktorD1m1trov,项目名称:T-Academy,代码行数:35,代码来源:PokerHandsCheckerTest.cs

示例7: TestCompareHandsFirstHand

 public void TestCompareHandsFirstHand()
 {
     Card cardOne = new Card(CardFace.Ace, CardSuit.Diamonds);
     Card cardTwo = new Card(CardFace.Ace, CardSuit.Hearts);
     Card cardThree = new Card(CardFace.Five, CardSuit.Spades);
     Card cardFour = new Card(CardFace.Ace, CardSuit.Clubs);
     Card cardFive = new Card(CardFace.Ace, CardSuit.Spades);
     IList<ICard> cardsOne = new List<ICard>();
     cardsOne.Add(cardOne);
     cardsOne.Add(cardTwo);
     cardsOne.Add(cardThree);
     cardsOne.Add(cardFour);
     cardsOne.Add(cardFive);
     Hand handOne = new Hand(cardsOne);
     Card cardSix = new Card(CardFace.Two, CardSuit.Diamonds);
     Card cardSeven = new Card(CardFace.Jack, CardSuit.Hearts);
     Card cardEight = new Card(CardFace.Five, CardSuit.Spades);
     Card cardNine = new Card(CardFace.Ace, CardSuit.Clubs);
     Card cardTen = new Card(CardFace.Ten, CardSuit.Clubs);
     IList<ICard> cardsTwo = new List<ICard>();
     cardsTwo.Add(cardSix);
     cardsTwo.Add(cardSeven);
     cardsTwo.Add(cardEight);
     cardsTwo.Add(cardNine);
     cardsTwo.Add(cardTen);
     Hand handTwo = new Hand(cardsTwo);
     PokerHandsChecker poker = new PokerHandsChecker();
     int result = poker.CompareHands(handOne, handTwo);
     Assert.AreEqual(1, result, "CompareHands() method in class PokerHandsChecker is not working correctly.");
 }
开发者ID:danielkaradaliev,项目名称:TelerikAcademyAssignments,代码行数:30,代码来源:CompareHandsTests.cs

示例8: TestEmptyHand

 public void TestEmptyHand()
 {
     Hand hand = new Hand(new List<ICard>());
     string handToString = hand.ToString();
     Assert.AreEqual(string.Empty, handToString,
         "ToString() method in class Hand is not working correctly.");
 }
开发者ID:krumov,项目名称:telerik,代码行数:7,代码来源:HandToStringTest.cs

示例9: CheckPlay

        public static PokerPlay CheckPlay(Hand hand)
        {
            if (5 > hand.Cards.Count())
                throw new NotEnoughCardsException();

            var play = PokerPlay.None;

            var countCardValues = GeneratePlayDictionary();
            foreach (var card in hand.Cards)
            {
                countCardValues[card.Value]++;
            }
            foreach (var source in countCardValues.Where(x => x.Value == 0).Select(x => x.Key).ToArray())
            {
                countCardValues.Remove(source);
            }

            if (IsStraightFlush(hand, countCardValues)) play = PokerPlay.StraightFlush;
            else if (IsFourOfAKind(countCardValues)) play = PokerPlay.FourOfAKind;
            else if (IsFullHouse(countCardValues)) play = PokerPlay.FullHouse;
            else if (IsFlush(hand)) play = PokerPlay.Flush;
            else if (IsStraight(countCardValues)) play = PokerPlay.Straight;
            else if (IsThreeOfAKind(countCardValues)) play = PokerPlay.ThreeOfAKind;
            else if (IsTwoPairs(countCardValues)) play = PokerPlay.TwoPair;
            else if (IsPair(countCardValues)) play = PokerPlay.Pair;

            return play;
        }
开发者ID:niltsiar,项目名称:poker-tdd-csharp,代码行数:28,代码来源:PokerRules.cs

示例10: CompareHands_OneOnTwoPairsFirstWithHigherKicker

        public void CompareHands_OneOnTwoPairsFirstWithHigherKicker()
        {
            IList<ICard> cardsFirstHand = new List<ICard>();
            cardsFirstHand.Add(new Card(CardFace.Ace, CardSuit.Diamonds));
            cardsFirstHand.Add(new Card(CardFace.Four, CardSuit.Spades)); // kicker 1 (higher)
            cardsFirstHand.Add(new Card(CardFace.King, CardSuit.Spades));
            cardsFirstHand.Add(new Card(CardFace.Ace, CardSuit.Clubs));
            cardsFirstHand.Add(new Card(CardFace.King, CardSuit.Hearts));

            IHand firstHand = new Hand(cardsFirstHand);

            IList<ICard> cardsSecondHand = new List<ICard>();
            cardsSecondHand.Add(new Card(CardFace.Ace, CardSuit.Hearts));
            cardsSecondHand.Add(new Card(CardFace.King, CardSuit.Diamonds));
            cardsSecondHand.Add(new Card(CardFace.King, CardSuit.Clubs));
            cardsSecondHand.Add(new Card(CardFace.Ace, CardSuit.Spades));
            cardsSecondHand.Add(new Card(CardFace.Three, CardSuit.Hearts)); // kicker 2

            IHand secondHand = new Hand(cardsSecondHand);

            PokerHandsChecker checker = new PokerHandsChecker();

            int result = checker.CompareHands(firstHand, secondHand);

            Assert.AreEqual(1, result);
        }
开发者ID:Rokata,项目名称:TelerikAcademy,代码行数:26,代码来源:PokerComparerTest.cs

示例11: PokerHandCheckerCompareHandsStrongerToWeakerTest

        public void PokerHandCheckerCompareHandsStrongerToWeakerTest()
        {
            IList<ICard> firstCardsSet = new List<ICard>()
            {
                new Card(CardFace.Four, CardSuit.Clubs),
                new Card(CardFace.Three, CardSuit.Clubs),
                new Card(CardFace.Two, CardSuit.Clubs),
                new Card(CardFace.Six, CardSuit.Clubs),
                new Card(CardFace.Five, CardSuit.Clubs)
            };

            IList<ICard> secondCardsSet = new List<ICard>()
            {
                new Card(CardFace.Ten, CardSuit.Clubs),
                new Card(CardFace.King, CardSuit.Spades),
                new Card(CardFace.Jack, CardSuit.Hearts),
                new Card(CardFace.Queen, CardSuit.Diamonds),
                new Card(CardFace.Ace, CardSuit.Hearts)
            };

            IHand firstHand = new Hand(firstCardsSet);
            IHand secondHand = new Hand(secondCardsSet);
            int result = handsChecker.CompareHands(firstHand, secondHand);
            int expected = 1;

            Assert.AreEqual(expected, result, "Stronger hand is incorrectly compared to weaker one.");
        }
开发者ID:Velmond,项目名称:TelerikAcademy-CSharp,代码行数:27,代码来源:PokerHandCheckerTests.cs

示例12: CompareHands_MinusOneOnSteelWheelAndHigherStraight

        public void CompareHands_MinusOneOnSteelWheelAndHigherStraight()
        {
            IList<ICard> cardsFirstHand = new List<ICard>();
            cardsFirstHand.Add(new Card(CardFace.Five, CardSuit.Clubs));
            cardsFirstHand.Add(new Card(CardFace.Ace, CardSuit.Spades));
            cardsFirstHand.Add(new Card(CardFace.Two, CardSuit.Diamonds));
            cardsFirstHand.Add(new Card(CardFace.Four, CardSuit.Spades));
            cardsFirstHand.Add(new Card(CardFace.Three, CardSuit.Hearts));

            IHand firstHand = new Hand(cardsFirstHand);

            IList<ICard> cardsSecondHand = new List<ICard>();
            cardsSecondHand.Add(new Card(CardFace.Seven, CardSuit.Diamonds));
            cardsSecondHand.Add(new Card(CardFace.Five, CardSuit.Spades));
            cardsSecondHand.Add(new Card(CardFace.Four, CardSuit.Diamonds));
            cardsSecondHand.Add(new Card(CardFace.Three, CardSuit.Clubs));
            cardsSecondHand.Add(new Card(CardFace.Six, CardSuit.Hearts));

            IHand secondHand = new Hand(cardsSecondHand);

            PokerHandsChecker checker = new PokerHandsChecker();

            int result = checker.CompareHands(firstHand, secondHand);

            Assert.AreEqual(-1, result);
        }
开发者ID:Rokata,项目名称:TelerikAcademy,代码行数:26,代码来源:PokerComparerTest.cs

示例13: CompareHands_MinusOneOnSimilarThrees

        public void CompareHands_MinusOneOnSimilarThrees()
        {
            IList<ICard> cardsFirstHand = new List<ICard>();
            cardsFirstHand.Add(new Card(CardFace.Eight, CardSuit.Clubs)); // kicker 1
            cardsFirstHand.Add(new Card(CardFace.Four, CardSuit.Spades));
            cardsFirstHand.Add(new Card(CardFace.Four, CardSuit.Diamonds));
            cardsFirstHand.Add(new Card(CardFace.Four, CardSuit.Clubs));
            cardsFirstHand.Add(new Card(CardFace.Seven, CardSuit.Diamonds)); // kicker 2

            IHand firstHand = new Hand(cardsFirstHand);

            IList<ICard> cardsSecondHand = new List<ICard>();
            cardsSecondHand.Add(new Card(CardFace.Four, CardSuit.Diamonds));
            cardsSecondHand.Add(new Card(CardFace.Four, CardSuit.Spades));
            cardsSecondHand.Add(new Card(CardFace.Nine, CardSuit.Diamonds)); // kicker 1
            cardsSecondHand.Add(new Card(CardFace.Two, CardSuit.Clubs));
            cardsSecondHand.Add(new Card(CardFace.Four, CardSuit.Clubs)); // kicker 2

            IHand secondHand = new Hand(cardsSecondHand);

            PokerHandsChecker checker = new PokerHandsChecker();

            int result = checker.CompareHands(firstHand, secondHand);

            Assert.AreEqual(-1, result);
        }
开发者ID:Rokata,项目名称:TelerikAcademy,代码行数:26,代码来源:PokerComparerTest.cs

示例14: TestIsFlushFiveDifferentFaceEaqualSuitsNotSerial

        public void TestIsFlushFiveDifferentFaceEaqualSuitsNotSerial()
        {
            IList<ICard> cards = new List<ICard>();

            Card card1 = new Card(CardFace.Ace, CardSuit.Spades);
            cards.Add(card1);

            Card card2 = new Card(CardFace.Ten, CardSuit.Spades);
            cards.Add(card2);

            Card card3 = new Card(CardFace.Queen, CardSuit.Spades);
            cards.Add(card3);

            Card card4 = new Card(CardFace.Jack, CardSuit.Spades);
            cards.Add(card4);

            Card card5 = new Card(CardFace.Seven, CardSuit.Spades);
            cards.Add(card5);

            Hand hand = new Hand(cards);
            PokerHandsChecker checker = new PokerHandsChecker();

            bool actual = checker.IsFlush(hand);
            bool expected = true;

            Assert.AreEqual(expected, actual);
        }
开发者ID:ValMomchilova,项目名称:TelerikAcademyHomeWorks,代码行数:27,代码来源:HandTests.cs

示例15: Main

        static void Main()
        {
            ICard card = new Card(CardFace.Ace, CardSuit.Clubs);
            Console.WriteLine(card);

            IHand hand = new Hand(new List<ICard>() { 
                new Card(CardFace.Ace, CardSuit.Clubs),
                new Card(CardFace.Ace, CardSuit.Diamonds),
                new Card(CardFace.King, CardSuit.Hearts),
                new Card(CardFace.King, CardSuit.Spades),
                new Card(CardFace.Seven, CardSuit.Diamonds),
            });
            Console.WriteLine(hand);

            IPokerHandsChecker checker = new PokerHandsChecker();
            Console.WriteLine(checker.IsValidHand(hand));
            Console.WriteLine(checker.IsOnePair(hand));
            Console.WriteLine(checker.IsTwoPair(hand));

            var card1 = new Card(CardFace.Jack, CardSuit.Clubs);
            var card2 = new Card(CardFace.Nine, CardSuit.Diamonds);
            var card3 = new Card(CardFace.Four, CardSuit.Spades);
            var card4 = new Card(CardFace.Two, CardSuit.Hearts);
            var card5 = new Card(CardFace.Queen, CardSuit.Hearts);

            var hand2 = new Hand(new List<ICard> { card1, card2, card3, card4, card5 });
            Console.WriteLine(hand2);
        }
开发者ID:MarKamenov,项目名称:TelerikAcademy,代码行数:28,代码来源:PokerExample.cs


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