Наследование: IPokerHandsChecker
        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));
        }
Пример #2
0
        public static void Main()
        {
            XmlConfigurator.Configure();
            Log.Info("Info logging");
            try
            {
                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.Jack, CardSuit.Diamonds),
                    new Card(CardFace.King, CardSuit.Hearts),
                    new Card(CardFace.Ten, CardSuit.Spades),
                    new Card(CardFace.Queen, CardSuit.Diamonds),
                });

                Console.WriteLine(hand);
                IPokerHandsChecker checker = new PokerHandsChecker();
                Console.WriteLine("Valid hand? : {0}", checker.IsValidHand(hand));
                Console.WriteLine("Is Straight : {0}", checker.IsStraight(hand));
                Console.WriteLine("Is one pair : {0}", checker.IsOnePair(hand));
                Console.WriteLine("Is two pair : {0}", checker.IsTwoPair(hand));
            }
            catch (Exception e)
            {
                Log.Error("This is my error", e);
            }
        }
        public void CompareHandsTestSecondEqualToFirst()
        {
            PokerHandsChecker checker = new PokerHandsChecker();

            Hand firstHand = new Hand(new List<ICard>()
            {
                new Card(CardFace.King, CardSuit.Spades),
                new Card(CardFace.King, CardSuit.Diamonds),
                new Card(CardFace.King, CardSuit.Clubs),
                new Card(CardFace.Queen, CardSuit.Spades),
                new Card(CardFace.Queen, CardSuit.Clubs)
            });

            Hand secondHand = new Hand(new List<ICard>()
            {
                new Card(CardFace.King, CardSuit.Spades),
                new Card(CardFace.King, CardSuit.Diamonds),
                new Card(CardFace.King, CardSuit.Clubs),
                new Card(CardFace.Queen, CardSuit.Spades),
                new Card(CardFace.Queen, CardSuit.Clubs)
            });

            int expectedResult = 0;
            int actual;
            actual = checker.CompareHands(firstHand, secondHand);
            Assert.AreEqual(expectedResult, actual);
        }
Пример #4
0
        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));
        }
Пример #5
0
        private static void Main()
        {
            try
            {
                IHand hand = new Hand(new List<ICard>() 
                { 
                    new Card(CardFace.Ace, CardSuit.Clubs),
                    new Card(CardFace.Queen, CardSuit.Clubs),
                    new Card(CardFace.King, CardSuit.Clubs),
                    new Card(CardFace.Jack, CardSuit.Clubs),
                    new Card(CardFace.Ten, CardSuit.Clubs),
                });
                Console.WriteLine(hand);
                IPokerHandsChecker checker = new PokerHandsChecker();

                Console.WriteLine(checker.IsValidHand(hand) ? "Hand is valid." : "Hand is not valid!");
                Console.WriteLine(checker.IsRoyalFlush(hand) ? "Royal flush." : "Hand is not Royal flush!");
                Console.WriteLine(checker.IsStraightFlush(hand) ? "Straight flush." : "Hand is not Straight flush!");
                Console.WriteLine(checker.IsFlush(hand) ? "Flush." : "Hand is not Flush!");
                Console.WriteLine(checker.IsStraight(hand) ? "Straight." : "Hand is not Straight!");
                Console.WriteLine(checker.IsFullHouse(hand) ? "Full house." : "Hand is not Full house!");
                Console.WriteLine(checker.IsFourOfAKind(hand) ? "Four of a kind." : "Hand is not Four of a kind!");
                Console.WriteLine(checker.IsThreeOfAKind(hand) ? "Three of a kind." : "Hand is not Three of a kind!");

                IHand hand1 = new Hand("K♥ J♥ 8♣ 7♦ 4♠");
                Console.WriteLine(hand1);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
        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);
        }
        public void CompareHands_EqualFlushes()
        {
            IList<ICard> firstHandCards = new List<ICard>
            {
                new Card(CardFace.Queen, CardSuit.Hearts),
                new Card(CardFace.Ten, CardSuit.Hearts),
                new Card(CardFace.Seven, CardSuit.Hearts),
                new Card(CardFace.Five, CardSuit.Hearts),
                new Card(CardFace.Three, CardSuit.Hearts),
            };

            IList<ICard> secondHandCards = new List<ICard>
            {
                new Card(CardFace.Queen, CardSuit.Clubs),
                new Card(CardFace.Ten, CardSuit.Clubs),
                new Card(CardFace.Seven, CardSuit.Clubs),
                new Card(CardFace.Five, CardSuit.Clubs),
                new Card(CardFace.Three, CardSuit.Clubs),
            };

            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);
        }
 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.");
 }
        public void CompareHandsTestFirstBetterThanSecond()
        {
            PokerHandsChecker checker = new PokerHandsChecker();

            Hand firstHand = new Hand(new List<ICard>()
            {
                new Card(CardFace.Ace, CardSuit.Spades),
                new Card(CardFace.King, CardSuit.Spades),
                new Card(CardFace.Jack, CardSuit.Spades),
                new Card(CardFace.Queen, CardSuit.Spades),
                new Card(CardFace.Ten, CardSuit.Spades)
            });

            Hand secondHand = new Hand(new List<ICard>()
            {
                new Card(CardFace.Ace, CardSuit.Spades),
                new Card(CardFace.King, CardSuit.Spades),
                new Card(CardFace.Jack, CardSuit.Spades),
                new Card(CardFace.Ten, CardSuit.Spades),
                new Card(CardFace.Ten, CardSuit.Spades)
            });

            int expectedResult = -1;
            int actual;
            actual = checker.CompareHands(firstHand, secondHand);
            Assert.AreEqual(expectedResult, actual);
        }
Пример #10
0
        public void HighCardTrueTest()
        {
            var card1 = new Card(CardFace.King, CardSuit.Hearts);
            var card2 = new Card(CardFace.Five, CardSuit.Spades);
            var card3 = new Card(CardFace.Seven, CardSuit.Diamonds);
            var card4 = new Card(CardFace.Ten, CardSuit.Clubs);
            var card5 = new Card(CardFace.Two, CardSuit.Spades);

            var cards = new List<ICard>();
            cards.Add(card1);
            cards.Add(card2);
            cards.Add(card3);
            cards.Add(card4);
            cards.Add(card5);

            // ♣
            // ♦
            // ♥
            // ♠

            Hand hand = new Hand(cards);

            bool expected = true;
            PokerHandsChecker checker = new PokerHandsChecker();
            bool actual = checker.IsHighCard(hand);
            Assert.AreEqual(expected, actual);
        }
        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.IsStraight(hand));
            Console.WriteLine(checker.IsOnePair(hand));
            Console.WriteLine(checker.IsTwoPair(hand));
            Console.WriteLine(checker.IsStraightFlush(hand));
            Console.WriteLine(checker.IsFlush(hand));
            Console.WriteLine(checker.IsFourOfAKind(hand));
            Console.WriteLine(checker.IsThreeOfAKind(hand));
            Console.WriteLine(checker.IsHighCard(hand));
            Console.WriteLine(checker.IsFullHouse(hand));
        }
        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);
        }
Пример #13
0
        public bool IsFourOfAKind(IHand hand)
        {
            PokerHandsChecker checker = new PokerHandsChecker();
            if (!checker.IsValidHand(hand))
            {
                return false;
            }

            int counter = 0;
            for (int i = 0; i < hand.Cards.Count; i++)
            {
                for (int j = 0; j < hand.Cards.Count; j++)
                {
                    if (hand.Cards[i].Face == hand.Cards[j].Face)
                    {
                        counter++;
                    }
                }
                if (counter == 4)
                {
                    return true;
                }

                counter = 0;
            }

            return false;
        }
Пример #14
0
        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);
        }
Пример #15
0
        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);
        }
        public void TestIsValid2()
        {
            IPokerHandsChecker checker = new PokerHandsChecker();
            bool validHand = checker.IsValidHand(null);

            Assert.AreEqual(false, validHand, "Hand validation was not successful.");
        }
Пример #17
0
        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);
        }
        public void TestIsValid4()
        {
            IHand hand = new Hand("A♦ 10♦ Q♦ J♦ 10♦");

            PokerHandsChecker checker = new PokerHandsChecker();

            Assert.IsFalse(checker.IsValidHand(hand), "Hand validation was not successful.");
        }
        public void TestIsFlushHandWithInvalidFlush()
        {
            PokerHandsChecker checker = new PokerHandsChecker();

            var cards = GenerateCorectCards();
            var hand = new Hand(cards);
            bool isflush = checker.IsFlush(hand);

            Assert.IsFalse(isflush, "Hand is invalid flush and result mast be false.");
        }
Пример #20
0
        public void IsValidHandShouldReturnFalseIfSameCardAddedMoreThanOnce()
        {
            var hand = new Hand(deck.GetRange(0,4));
            hand.Cards.Add(deck[0]);
            var pokerHandsChecker = new PokerHandsChecker();

            var result = pokerHandsChecker.IsValidHand(hand);

            Assert.IsFalse(result);
        }
        public void IsValidHandWithTwoCardsTest()
        {
            Hand pokerHand = new Hand(new List<ICard>(){ 
                                new Card(CardFace.Ace, CardSuit.Hearts),
                                new Card(CardFace.King, CardSuit.Diamonds)});

            PokerHandsChecker checker = new PokerHandsChecker();
            bool isValidHand = checker.IsValidHand(pokerHand);
            Assert.AreEqual(false, isValidHand);
        }
Пример #22
0
        public void IsValidHandShouldReturnFalseIfTwoDifferentCardsAreEqual()
        {
            var hand = new Hand(deck.GetRange(0, 3));
            hand.Cards.Add(new Card(CardFace.Ace, CardSuit.Spades));
            hand.Cards.Add(new Card(CardFace.Ace, CardSuit.Spades));
            var pokerHandsChecker = new PokerHandsChecker();

            var result = pokerHandsChecker.IsValidHand(hand);

            Assert.IsFalse(result);
        }
Пример #23
0
        public void InvalidHandWithThreeDifferentCards()
        {
            var hand = new Hand(new List<ICard>() {
                new Card(CardFace.Seven, CardSuit.Clubs),
                new Card(CardFace.King, CardSuit.Hearts),
                new Card(CardFace.Three, CardSuit.Spades)
            });

            var checker = new PokerHandsChecker();
            Assert.IsFalse(checker.IsValidHand(hand));
        }
        public void TestIsNotFlushHandIfLessThan5Cards()
        {
            IList<ICard> cards = new List<ICard>()
            {
                new Card(CardFace.Two, CardSuit.Diamonds)
            };

            Hand hand = new Hand(cards);
            PokerHandsChecker checker = new PokerHandsChecker();
            Assert.IsFalse(checker.IsFlush(hand));
        }
        public void IsFourOfAKindTest()
        {
            Hand pokerHand = new Hand(new List<ICard>(){ 
                                new Card(CardFace.Ace, CardSuit.Hearts),
                                new Card(CardFace.Jack, CardSuit.Diamonds),
                                new Card(CardFace.Jack, CardSuit.Spades),
                                new Card(CardFace.Jack, CardSuit.Clubs), 
                                new Card(CardFace.Jack, CardSuit.Hearts)});

            PokerHandsChecker checker = new PokerHandsChecker();
            Assert.AreEqual(true, checker.IsFourOfAKind(pokerHand));
        }
        public void IsFlushTest()
        {
            Hand pokerHand = new Hand(new List<ICard>(){ 
                                new Card(CardFace.Ace, CardSuit.Hearts),
                                new Card(CardFace.King, CardSuit.Hearts),
                                new Card(CardFace.Queen, CardSuit.Hearts),
                                new Card(CardFace.Jack, CardSuit.Hearts),
                                new Card(CardFace.Nine, CardSuit.Hearts)});

            PokerHandsChecker checker = new PokerHandsChecker();
            Assert.AreEqual(true, checker.IsFlush(pokerHand));
        }
 public void TestForFourOfAKind()
 {
     IList<ICard> cardList = new List<ICard>();
     cardList.Add(new Card(CardFace.King, CardSuit.Spades));
     cardList.Add(new Card(CardFace.King, CardSuit.Hearts));
     cardList.Add(new Card(CardFace.King, CardSuit.Diamonds));
     cardList.Add(new Card(CardFace.King, CardSuit.Clubs));
     cardList.Add(new Card(CardFace.Ten, CardSuit.Hearts));
     var hand = new Hand(cardList);
     var handChecker = new PokerHandsChecker();
     Assert.AreEqual(true, handChecker.IsFourOfAKind(hand));
 }
        public void ExpectIsValidToReturnFalseWhenPokeHandIsInvalidBecauseItHasLessThanFiveCards()
        {
            List<ICard> cards = new List<ICard>();
            cards.Add(new Card(CardFace.Ace, CardSuit.Clubs));
            cards.Add(new Card(CardFace.Ace, CardSuit.Diamonds));
            cards.Add(new Card(CardFace.Ace, CardSuit.Hearts));
            cards.Add(new Card(CardFace.Ace, CardSuit.Spades));

            Hand hand = new Hand(cards);
            PokerHandsChecker checker = new PokerHandsChecker();
            Assert.AreEqual(false, checker.IsValidHand(hand));
        }
 public void TestInvalidHand()
 {
     IList<ICard> cardList = new List<ICard>();
     cardList.Add(new Card(CardFace.King, CardSuit.Hearts));
     cardList.Add(new Card(CardFace.Queen, CardSuit.Diamonds));
     cardList.Add(new Card(CardFace.Ace, CardSuit.Spades));
     cardList.Add(new Card(CardFace.Jack, CardSuit.Clubs));
     cardList.Add(new Card(CardFace.Ace, CardSuit.Spades));
     var hand = new Hand(cardList);
     var handChecker = new PokerHandsChecker();
     Assert.AreEqual(false, handChecker.IsValidHand(hand));
 }
 public void TestForFlush()
 {
     IList<ICard> cardList = new List<ICard>();
     cardList.Add(new Card(CardFace.King, CardSuit.Hearts));
     cardList.Add(new Card(CardFace.Queen, CardSuit.Hearts));
     cardList.Add(new Card(CardFace.Ace, CardSuit.Hearts));
     cardList.Add(new Card(CardFace.Jack, CardSuit.Hearts));
     cardList.Add(new Card(CardFace.Ten, CardSuit.Hearts));
     var hand = new Hand(cardList);
     var handChecker = new PokerHandsChecker();
     Assert.AreEqual(true, handChecker.IsFlush(hand));
 }
Пример #31
0
        /// <summary>
        /// The main.
        /// </summary>
        private 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));
        }
Пример #32
0
        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));
        }
Пример #33
0
        static void Main()
        {
            ICard card = new Card(CardFace.Ace, CardSuit.Clubs);

            Console.WriteLine(card);

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

            Console.WriteLine(hand);

            IPokerHandsChecker checker = new PokerHandsChecker();

            Console.WriteLine(checker.IsValidHand(hand));
            Console.WriteLine(checker.IsFlush(hand));
            Console.WriteLine(checker.IsOnePair(hand));
            Console.WriteLine(checker.IsFourOfAKind(hand));
        }
Пример #34
0
        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));



            IHand hand2 = new Hand(new List <ICard>()
            {
                new Card(CardFace.Four, CardSuit.Clubs),
                new Card(CardFace.Five, CardSuit.Clubs),
                new Card(CardFace.Six, CardSuit.Clubs),
                new Card(CardFace.Seven, CardSuit.Clubs),
                new Card(CardFace.Eight, CardSuit.Clubs),
            });

            Console.WriteLine(checker.IsStraightFlush(hand2));
        }
Пример #35
0
        static void Main()
        {
            ICard card = new Card(CardFace.Ace, CardSuit.Clubs);

            Console.WriteLine("Current card is: " + card + Environment.NewLine);

            ///Normal hand\\\
            IHand hand = new Hand(new List <ICard>()
            {
                new Card(CardFace.Three, CardSuit.Clubs),
                new Card(CardFace.Six, CardSuit.Diamonds),
                new Card(CardFace.King, CardSuit.Hearts),
                new Card(CardFace.Two, CardSuit.Spades),
                new Card(CardFace.Seven, CardSuit.Diamonds),
            });

            /////Flush\\\
            //IHand hand = new Hand(new List<ICard>() {
            //    new Card(CardFace.Ace, CardSuit.Clubs),
            //    new Card(CardFace.Ace, CardSuit.Clubs),
            //    new Card(CardFace.King, CardSuit.Clubs),
            //    new Card(CardFace.King, CardSuit.Clubs),
            //    new Card(CardFace.Seven, CardSuit.Clubs),
            //});

            /////Four of a kind\\\
            //IHand hand = new Hand(new List<ICard>() {
            //    new Card(CardFace.Ace, CardSuit.Clubs),
            //    new Card(CardFace.Ace, CardSuit.Diamonds),
            //    new Card(CardFace.Ace, CardSuit.Hearts),
            //    new Card(CardFace.Ace, CardSuit.Spades),
            //    new Card(CardFace.Eight, CardSuit.Clubs),
            //});

            /////One pair\\\
            //IHand hand = new Hand(new List<ICard>() {
            //    new Card(CardFace.Ace, CardSuit.Clubs),
            //    new Card(CardFace.Ace, CardSuit.Diamonds),
            //    new Card(CardFace.Five, CardSuit.Hearts),
            //    new Card(CardFace.Jack, CardSuit.Spades),
            //    new Card(CardFace.Eight, CardSuit.Clubs),
            //});

            /////Two pairs\\\
            //IHand hand = new Hand(new List<ICard>() {
            //    new Card(CardFace.Ace, CardSuit.Clubs),
            //    new Card(CardFace.Ace, CardSuit.Diamonds),
            //    new Card(CardFace.Five, CardSuit.Hearts),
            //    new Card(CardFace.Jack, CardSuit.Spades),
            //    new Card(CardFace.Jack, CardSuit.Clubs),
            //});

            /////Straight Flush\\\
            //IHand hand = new Hand(new List<ICard>() {
            //    new Card(CardFace.Jack, CardSuit.Clubs),
            //    new Card(CardFace.Ten, CardSuit.Clubs),
            //    new Card(CardFace.Nine, CardSuit.Clubs),
            //    new Card(CardFace.Eight, CardSuit.Clubs),
            //    new Card(CardFace.Seven, CardSuit.Clubs),
            //});

            /////Full House\\\
            //IHand hand = new Hand(new List<ICard>() {
            //    new Card(CardFace.Six, CardSuit.Diamonds),
            //    new Card(CardFace.Six, CardSuit.Hearts),
            //    new Card(CardFace.Nine, CardSuit.Clubs),
            //    new Card(CardFace.Nine, CardSuit.Spades),
            //    new Card(CardFace.Nine, CardSuit.Clubs),
            //});

            /////Straight\\\
            //IHand hand = new Hand(new List<ICard>() {
            //    new Card(CardFace.King, CardSuit.Diamonds),
            //    new Card(CardFace.Queen, CardSuit.Hearts),
            //    new Card(CardFace.Jack, CardSuit.Clubs),
            //    new Card(CardFace.Ten, CardSuit.Spades),
            //    new Card(CardFace.Nine, CardSuit.Clubs),
            //});

            Console.WriteLine(hand + Environment.NewLine);

            IPokerHandsChecker checker = new PokerHandsChecker();

            Console.WriteLine("Is this hand valid: " + checker.IsValidHand(hand));
            Console.WriteLine("Do you have one pair: " + checker.IsOnePair(hand));
            Console.WriteLine("Do you have two pairs: " + checker.IsTwoPair(hand));
            Console.WriteLine("Do you have a flush: " + checker.IsFlush(hand));
            Console.WriteLine("Do you have four of a kind: " + checker.IsFourOfAKind(hand));
            Console.WriteLine("Do you have three of a kind: " + checker.IsThreeOfAKind(hand));
            Console.WriteLine("Do you have straight flush: " + checker.IsStraightFlush(hand));
            Console.WriteLine("Do you have a full house: " + checker.IsFullHouse(hand));
            Console.WriteLine("Do you have a straight: " + checker.IsStraight(hand));
            Console.WriteLine("Do you have high card: " + checker.IsHighCard(hand));
        }