Example #1
0
        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);
        }
Example #2
0
 private bool TypesArentEqual(PokerHand other)
 {
     return TypeOfHand != other.TypeOfHand;
 }
Example #3
0
 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);
 }
Example #4
0
 private bool MyTypeIsBetter(PokerHand other)
 {
     return TypeOfHand > other.TypeOfHand;
 }
Example #5
0
        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;
        }