Exemplo n.º 1
0
        public Pair(List <Card> cards)
        {
            this.highestPair = HandUtils.GetHighestValueDuplicateSet(cards, cardsInPair);
            List <Card> cardsNotInPair = HandUtils.GetCardsNotInSet(cards, this.highestPair);

            this.kickerCards = HandUtils.GetHighestValueSortedSubset(cardsInPairKicker, cardsNotInPair);
        }
Exemplo n.º 2
0
        public ThreeOfAKind(List <Card> cards)
        {
            this.highestThreeOfAKind = HandUtils.GetHighestValueDuplicateSet(cards, this.cardsInThreeOfAKind);
            List <Card> cardsNotInThreeOfAKind = HandUtils.GetCardsNotInSet(cards, this.highestThreeOfAKind);

            this.kickerCards = HandUtils.GetHighestValueSortedSubset(cardsInThreeOfAKindKicker, cardsNotInThreeOfAKind);
        }
        public void GetHighestValueFlush_ReturnsHighestValueSetOfCardsSatisfyingAFlushOfAtLeastTheSpecifiedSize()
        {
            List <Card> cards = TestUtil.CreateTestFlushCards(Suit.Diamond, new int[] { 2, 4, 6, 8, 10 });

            List <Card> result = HandUtils.GetHighestValueFlush(cards, 5);

            Assert.AreEqual(result.Count, 5);
        }
Exemplo n.º 4
0
        public override int CompareTo(Hand other)
        {
            if (!(other is Flush))
            {
                throw new Exception("Cannot compare flush hand not non-flush hand");
            }

            return(HandUtils.CompareSortedCardLists(this.flushCards, ((Flush)other).flushCards));
        }
Exemplo n.º 5
0
        public override int CompareTo(Hand other)
        {
            if (!(other is HighCard))
            {
                throw new Exception("Cannot compare high card hand not non-high card hand");
            }

            return(HandUtils.CompareSortedCardLists(this.sortedCards, ((HighCard)other).sortedCards));
        }
        public void GetCardsNotInSet_ReturnsASetOfCardsWithTheSecondSetExcluded()
        {
            List <Card> cards1 = TestUtil.CreateTestFlushCards(Suit.Diamond, new int[] { 2, 4, 6, 8, 10 });
            List <Card> cards2 = TestUtil.CreateTestFlushCards(Suit.Diamond, new int[] { 2, 4, 8, 10, 12 });

            List <Card> result = HandUtils.GetCardsNotInSet(cards1, cards2);

            Assert.AreEqual(result.Count, 1);
            Assert.AreEqual(result[0], new Card(CardValue.Seven, Suit.Diamond));
        }
Exemplo n.º 7
0
        public static bool HandBusted(List <Card> userHand)
        {
            int userHandValue = HandUtils.CalculateHandValue(userHand).value;

            if (userHandValue > 21)
            {
                return(true);
            }
            return(false);
        }
        public void GetHighestValueSortedSubset_GetsASpecifiedSizeSubsetOfTheCardsWithTheHighestValue()
        {
            List <Card> cards = TestUtil.CreateTestFlushCards(Suit.Diamond, new int[] { 2, 4, 6, 8, 10 });

            List <Card> result = HandUtils.GetHighestValueSortedSubset(3, cards);

            Assert.AreEqual(result.Count, 3);
            Assert.AreEqual(result[0], new Card(CardValue.Jack, Suit.Diamond));
            Assert.AreEqual(result[1], new Card(CardValue.Nine, Suit.Diamond));
            Assert.AreEqual(result[2], new Card(CardValue.Seven, Suit.Diamond));
        }
        public void GetCountsOfCardsBySuit_ReturnsADictionaryMappingSuitsOfCardsToTheirFrequency()
        {
            List <Card> cards = new List <Card>
            {
                new Card(CardValue.Four, Suit.Club),
                new Card(CardValue.Jack, Suit.Club),
                new Card(CardValue.Ten, Suit.Club),
                new Card(CardValue.Queen, Suit.Club),
                new Card(CardValue.Jack, Suit.Heart)
            };

            Dictionary <Suit, int> result = HandUtils.GetCountsOfCardsBySuit(cards);

            Assert.AreEqual(result.Count, 2);
            Assert.AreEqual(result[Suit.Club], 4);
            Assert.AreEqual(result[Suit.Heart], 1);
        }
Exemplo n.º 10
0
        public void GetHighestValueDuplicateSet_ReturnsHighestValueSetOfCardsWithTheSpecifiedNumberOfDuplicates()
        {
            List <Card> cards = new List <Card>
            {
                new Card(CardValue.Queen, Suit.Club),
                new Card(CardValue.Jack, Suit.Club),
                new Card(CardValue.Queen, Suit.Heart),
                new Card(CardValue.Queen, Suit.Diamond),
                new Card(CardValue.Jack, Suit.Heart)
            };

            List <Card> result = HandUtils.GetHighestValueDuplicateSet(cards, 2);

            Assert.AreEqual(result.Count, 2);
            Assert.AreEqual(result[0].Value, CardValue.Jack);
            Assert.AreEqual(result[1].Value, CardValue.Jack);
        }
Exemplo n.º 11
0
        public void GetCountsOfCardsByValue_ReturnsADictionaryMappingValuesOfCardsToTheirFrequency()
        {
            List <Card> cards = new List <Card>
            {
                new Card(CardValue.Queen, Suit.Club),
                new Card(CardValue.Jack, Suit.Club),
                new Card(CardValue.Queen, Suit.Heart),
                new Card(CardValue.Queen, Suit.Diamond),
                new Card(CardValue.Jack, Suit.Heart)
            };

            Dictionary <CardValue, int> result = HandUtils.GetCountsOfCardsByValue(cards);

            Assert.AreEqual(result.Count, 2);
            Assert.AreEqual(result[CardValue.Queen], 3);
            Assert.AreEqual(result[CardValue.Jack], 2);
        }
Exemplo n.º 12
0
        public override int CompareTo(Hand other)
        {
            if (!(other is Pair))
            {
                throw new Exception("Cannot compare pair hand not non-pair hand");
            }

            Pair otherPair = (Pair)other;

            int pairComparison = this.highestPair[0].CompareTo(otherPair.highestPair[0]);

            if (pairComparison != 0)
            {
                return(pairComparison);
            }
            else
            {
                return(HandUtils.CompareSortedCardLists(this.kickerCards, otherPair.kickerCards));
            }
        }
Exemplo n.º 13
0
        public override int CompareTo(Hand other)
        {
            if (!(other is ThreeOfAKind))
            {
                throw new Exception("Cannot compare three-of-a-kind hand not non-three-of-a-kind hand");
            }

            ThreeOfAKind otherThreeOfAKind = (ThreeOfAKind)other;

            int threeOfAKindComparison = this.highestThreeOfAKind[0].CompareTo(otherThreeOfAKind.highestThreeOfAKind[0]);

            if (threeOfAKindComparison != 0)
            {
                return(threeOfAKindComparison);
            }
            else
            {
                return(HandUtils.CompareSortedCardLists(this.kickerCards, otherThreeOfAKind.kickerCards));
            }
        }
Exemplo n.º 14
0
        public void CompareSortedCardLists_ReturnsComparison()
        {
            List <Card> cards1 = new List <Card>
            {
                new Card(CardValue.Queen, Suit.Club),
                new Card(CardValue.Jack, Suit.Club),
                new Card(CardValue.Nine, Suit.Club),
                new Card(CardValue.Seven, Suit.Club),
                new Card(CardValue.Five, Suit.Heart)
            };
            List <Card> cards2 = new List <Card>
            {
                new Card(CardValue.Queen, Suit.Club),
                new Card(CardValue.Jack, Suit.Club),
                new Card(CardValue.Nine, Suit.Club),
                new Card(CardValue.Seven, Suit.Club),
                new Card(CardValue.Four, Suit.Heart)
            };

            Assert.IsTrue(HandUtils.CompareSortedCardLists(cards1, cards2) > 0);
        }
Exemplo n.º 15
0
 public HighCard(List <Card> cards)
 {
     this.sortedCards = HandUtils.GetHighestValueSortedSubset(this.handSize, cards);
 }
Exemplo n.º 16
0
 public Flush(List <Card> cards)
 {
     this.flushCards = HandUtils.GetHighestValueFlush(cards, handSize);
 }
Exemplo n.º 17
0
 public static bool HandIsBlackjack(List <Card> userHand)
 {
     return(userHand.Count == 2 && HandUtils.CalculateHandValue(userHand).value == 21);
 }