/// <summary> /// Compares two Full house hands. /// </summary> /// <param name="sortedHand1">The first hand sorted.</param> /// <param name="sortedHand2">The second hand sorted.</param> /// <returns>Less than zero if <paramref name="sortedHand1"/> ranks lower than /// <paramref name="sortedHand2"/>, zero if the hands are of equal value, /// greater than zero if <paramref name="sortedHand1"/> ranks higher than /// <paramref name="sortedHand2"/>.</returns> /// <remarks>A full house is a hand that contains three matching cards of one rank /// and two matching cards of another rank. Between two full houses, the one with /// the higher-ranking three cards wins. If two hands have the same three cards, /// the hand with the higher pair wins.</remarks> private int CompareFullHouseHands(IHand sortedHand1, IHand sortedHand2) { // Cards[2] in a sorted hand is guaranteed to be one of the group of three int groupOfThreeCompareResult = sortedHand1.Cards[2].CompareTo(sortedHand2.Cards[2]); if (groupOfThreeCompareResult != 0) { return(groupOfThreeCompareResult); } ICard hand1PairFirstCard = sortedHand1.Cards[3]; if (hand1PairFirstCard.CompareTo(sortedHand1.Cards[2]) == 0) { hand1PairFirstCard = sortedHand1.Cards[0]; } ICard hand2PairFirstCard = sortedHand2.Cards[3]; if (hand2PairFirstCard.CompareTo(sortedHand2.Cards[2]) == 0) { hand2PairFirstCard = sortedHand2.Cards[0]; } return(hand1PairFirstCard.CompareTo(hand2PairFirstCard)); }
/// <summary> /// Compares two Four of a kind hands. /// </summary> /// <param name="sortedHand1">The first hand sorted.</param> /// <param name="sortedHand2">The second hand sorted.</param> /// <returns>Less than zero if <paramref name="sortedHand1"/> ranks lower than /// <paramref name="sortedHand2"/>, zero if the hands are of equal value, /// greater than zero if <paramref name="sortedHand1"/> ranks higher than /// <paramref name="sortedHand2"/>.</returns> /// <remarks>Four of a kind (quads) is a hand that contains all four cards of one rank /// and any other (unmatched) card. Quads with higher-ranking cards defeat /// lower-ranking ones. If the hands contain the same quad, the unmatched card acts /// as a kicker. If two hands have the same kicker, they tie and the pot is split.</remarks> private int CompareFourOfAKindHands(IHand sortedHand1, IHand sortedHand2) { // Cards[1] in a sorted hand is guaranteed to be one of the quad int quadCompareResult = sortedHand1.Cards[1].CompareTo(sortedHand2.Cards[1]); if (quadCompareResult != 0) { return(quadCompareResult); } ICard hand1UnmatchedCard = sortedHand1.Cards[0]; if (hand1UnmatchedCard.CompareTo(sortedHand1.Cards[1]) == 0) { hand1UnmatchedCard = sortedHand1.Cards[4]; } ICard hand2UnmatchedCard = sortedHand2.Cards[0]; if (hand2UnmatchedCard.CompareTo(sortedHand2.Cards[1]) == 0) { hand2UnmatchedCard = sortedHand2.Cards[4]; } return(hand1UnmatchedCard.CompareTo(hand2UnmatchedCard)); }
/// <summary> /// Gets the cards in a Two pair hand. /// </summary> /// <param name="sortedHand">The two pair hand sorted.</param> /// <param name="kicker">The kicker.</param> /// <param name="higherPairFirstCard">The first card of the higher pair.</param> /// <param name="lowerPairFirstCard">The first card of the lower pair.</param> private void GetCardsInTwoPair(IHand sortedHand, out ICard kicker, out ICard higherPairFirstCard, out ICard lowerPairFirstCard) { kicker = sortedHand.Cards[0]; int kickerIndex = 0; if (kicker.CompareTo(sortedHand.Cards[1]) == 0) { kicker = sortedHand.Cards[2]; kickerIndex = 2; if (kicker.CompareTo(sortedHand.Cards[3]) == 0) { kicker = sortedHand.Cards[4]; kickerIndex = 4; } } if (kickerIndex == 0) { higherPairFirstCard = sortedHand.Cards[3]; lowerPairFirstCard = sortedHand.Cards[1]; } else if (kickerIndex == 2) { higherPairFirstCard = sortedHand.Cards[3]; lowerPairFirstCard = sortedHand.Cards[0]; } else { higherPairFirstCard = sortedHand.Cards[2]; lowerPairFirstCard = sortedHand.Cards[0]; } }
public static bool IsLesser(ICard card1, ICard card2) { if (card1 == null) { return(card2 != null); } else { return(card1.CompareTo(card2) < 0); } }
public static bool IsGreater(ICard card1, ICard card2) { if (card1 == null) { return(false); } else { return(card1.CompareTo(card2) > 0); } }
/// <summary> /// Determines whether [has repeated cards] [the specified cards]. /// </summary> /// <param name="cards">The cards.</param> /// <returns>True if the hand has repeated cards.</returns> private bool HasRepeatedCards(IList <ICard> cards) { for (int i = 0; i < cards.Count - 1; i++) { ICard current = cards[i]; for (int j = i + 1; j < cards.Count; j++) { ICard next = cards[j]; if (current.CompareTo(next) == 0) { return(true); } } } return(false); }