Exemple #1
0
 public int CompareTo(Card other)
 {
     if (type != other.type)
     {
         return(type.CompareTo(other.type));
     }
     return(rank.CompareTo(other.rank));
 }
Exemple #2
0
        public void TestCompareToSameObject()
        {
            var six = new CardRank(CardRank.RankNames.Six);

            var comp = six.CompareTo(six);

            Assert.True(comp == 0);
        }
Exemple #3
0
        public void TestCompareToGreater()
        {
            var six   = new CardRank(CardRank.RankNames.Six);
            var seven = new CardRank(CardRank.RankNames.Seven);

            var comp = six.CompareTo(seven);

            Assert.True(comp < 0);
        }
Exemple #4
0
        public void TestCompareToLess()
        {
            var six   = new CardRank(CardRank.RankNames.Six);
            var three = new CardRank(CardRank.RankNames.Three);

            var comp = six.CompareTo(three);

            Assert.True(comp > 0);
        }
    public int CompareTo(Card other)
    {
        if (ReferenceEquals(this, other))
        {
            return(0);
        }
        if (ReferenceEquals(null, other))
        {
            return(1);
        }
        var rankComparison = suit.CompareTo(other.suit);

        if (rankComparison != 0)
        {
            return(rankComparison);
        }
        return(rank.CompareTo(other.rank));
    }
Exemple #6
0
        /// <summary>
        /// Compares two straight 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 straight is a poker hand that contains five cards of sequential rank.
        /// A straight flush is a hand that contains five cards in sequence, all of the same suit.
        /// Two straights are ranked by comparing the highest card of each.
        /// Two straights with the same high card are of equal value, suits are not used
        /// to separate them. Aces can play low in straights and straight flushes.</remarks>
        private int CompareStraightHands(IHand sortedHand1, IHand sortedHand2)
        {
            CardRank hand1HighestRank = sortedHand1.Cards[4].Rank;

            if (sortedHand1.Cards[4].Rank == CardRank.Ace &&
                sortedHand1.Cards[3].Rank == CardRank.Five)
            {
                // a wheel
                hand1HighestRank = CardRank.Five;
            }

            CardRank hand2HighestRank = sortedHand2.Cards[4].Rank;

            if (sortedHand2.Cards[4].Rank == CardRank.Ace &&
                sortedHand2.Cards[3].Rank == CardRank.Five)
            {
                // a wheel
                hand2HighestRank = CardRank.Five;
            }

            return(hand1HighestRank.CompareTo(hand2HighestRank));
        }