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); }
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); }
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)); }
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)); }
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); }
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); }
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); }
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)); } }
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)); } }
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); }
public HighCard(List <Card> cards) { this.sortedCards = HandUtils.GetHighestValueSortedSubset(this.handSize, cards); }
public Flush(List <Card> cards) { this.flushCards = HandUtils.GetHighestValueFlush(cards, handSize); }
public static bool HandIsBlackjack(List <Card> userHand) { return(userHand.Count == 2 && HandUtils.CalculateHandValue(userHand).value == 21); }