public bool Beats(PokerHand other) { if (TypesArentEqual(other)) return MyTypeIsBetter(other); if (TypeOfHand == HandType.ThreeOfAKind) return MyMatchingCardsAreBetter(other); if (TypeOfHand == HandType.Pair) return MyMatchingCardsAreBetter(other); return MyHighCardIsBetter(other); }
private bool TypesArentEqual(PokerHand other) { return TypeOfHand != other.TypeOfHand; }
private bool MyMatchingCardsAreBetter(PokerHand other) { var myCardsValue = GetCardValueAsInt(CardsUsedInBestHand.FirstOrDefault()); var otherCardsValue = GetCardValueAsInt(other.CardsUsedInBestHand.FirstOrDefault()); if (myCardsValue != otherCardsValue) return myCardsValue > otherCardsValue; return MyHighCardIsBetter(other); }
private bool MyTypeIsBetter(PokerHand other) { return TypeOfHand > other.TypeOfHand; }
private bool MyHighCardIsBetter(PokerHand other) { var myCards = CardsOrderedByValue().Select(GetCardValueAsInt).ToArray(); var otherCards = other.CardsOrderedByValue().Select(GetCardValueAsInt).ToArray(); for (int i = 0; i < otherCards.Length; i++) { if (myCards[i] != otherCards[i]) return myCards[i] >= otherCards[i]; } return false; }