Beispiel #1
0
        /// <summary>
        /// Compares the specified hand to determine if it is of the same type as this comparer.
        /// </summary>
        /// <param name="hand">The hand to be compared.</param>
        /// <returns>
        /// a tuple specifying information about the comparison.
        /// <para>The first value returns the type of this comparer if the specified hand matches, otherwise it returns <see cref="Hands.HighCard"/>.</para>
        /// <para>The second value indicates the high card of the hand if there was a match, otherwise it returns <see cref="Rank.Two"/>.</para>
        /// </returns>
        public Tuple<Hands, Rank> Compare(IHand hand)
        {
            Argument.IsNotNull(() => hand);
            if (hand.Count < 5)
                return Tuple.Create<Hands, Rank>(0, 0);

            var suit = hand[0].Suit;
            if (hand.Cast<Card>().Any(card => suit != card.Suit))
            {
                // Found a different suit, not a flush.
                return Tuple.Create<Hands, Rank>(0, 0);
            }

            // High card will be the first card, since the hand is already sorted by rank.
            return Tuple.Create(Hands.Flush, hand[0].Rank);
        }