Пример #1
0
 //static so we don't change the order of the cards in the program
 //returns a string representing the hand that is passed in
 //pair of two;s, three aces, king high......
 public static string getHandValue(Hand t_h)
 {
     //sort and calc total so that total and totalValue are assigned
     Hand h = new Hand(t_h.hand);
     h.sort();
     h.calcTotal();
     //check to see what hand the hand contains
     //3 high, 4 high.....etc....
     if (h.handTotal == 0)
     {
         if (h.highestCardValue >= 2 && h.highestCardValue <= 10)
             return h.highestCardValue.ToString() + " High";
         else if (h.highestCardValue == 11)
             return "Jack High";
         else if (h.highestCardValue == 12)
             return "Queen High";
         else if (h.highestCardValue == 13)
             return "King High";
         else if (h.highestCardValue == 14)
             return "Ace High";
     }
     //pair of two's, pair of king's......
     else if (h.handTotal == 1)
     {
         if (h.highestCardValue >= 2 && h.highestCardValue <= 10)
             return "Pair of " + h.highestCardValue.ToString() + "'s";
         if (h.highestCardValue == 11)
             return "Pair of Jacks";
         if (h.highestCardValue == 12)
             return "Pair of Jacks";
         if (h.highestCardValue == 13)
             return "Pair of Jacks";
         if (h.highestCardValue == 14)
             return "Pair of Jacks";
     }
     //just do two pair
     else if (h.handTotal == 2)
         return "Two Pair";
     //Three 9's...etc....
     else if (h.handTotal == 3)
     {
         if (h.highestCardValue >= 2 && h.highestCardValue <= 10)
             return "Three " + h.highestCardValue.ToString() + "'s";
         else if (h.highestCardValue == 11)
             return "Three Jacks";
         else if (h.highestCardValue == 12)
             return "Three Queens";
         else if (h.highestCardValue == 13)
             return "Three Kings";
         else if (h.highestCardValue == 14)
             return "Three Aces";
     }
     //Straight, 8 high.....etc....
     else if (h.handTotal == 4)
     {
         if (h.highestCardValue >= 2 && h.highestCardValue <= 10)
             return "Straight, " + h.highestCardValue.ToString() + " High";
         else if (h.highestCardValue == 11)
             return "Straight, Jack High";
         else if (h.highestCardValue == 12)
             return "Straight, Queen High";
         else if (h.highestCardValue == 13)
             return "Straight, King High";
         else if (h.highestCardValue == 14)
             return "Straight, Ace High";
     }
     else if (h.handTotal == 5)
     {
         if (h.highestCardValue >= 2 && h.highestCardValue <= 10)
             return "Flush, " + h.highestCardValue.ToString() + " High";
         else if (h.highestCardValue == 11)
             return "Flush, Jack High";
         else if (h.highestCardValue == 12)
             return "Flush, Queen High";
         else if (h.highestCardValue == 13)
             return "Flush, King High";
         else if (h.highestCardValue == 14)
             return "Flush, Ace High";
     }
     else if (h.handTotal == 6)
         return "Full House";
     //Four 6's.
     else if (h.handTotal == 7)
     {
         if (h.highestCardValue >= 2 && h.highestCardValue <= 10)
             return "Four " + h.highestCardValue.ToString() + "'s";
         else if (h.highestCardValue == 11)
             return "Four Jacks";
         else if (h.highestCardValue == 12)
             return "Four Queens";
         else if (h.highestCardValue == 13)
             return "Four Kings";
         else if (h.highestCardValue == 14)
             return "Four Aces";
     }
     else if (h.handTotal == 8)
         return "Has Straight Flush";
     else if (h.handTotal == 9)
         return "HOLY F*****G SHIT ROYAL FLUSH";
     //we won't make it this far
     return "Something went wrong...";
 }
Пример #2
0
        //returns true if lhs won
        //else return false
        public static bool won(Hand t_lhs,Hand t_rhs)
        {
            //We don't want to chage the order of the cards in the program,
            //so we need some temp hands.
            Hand lhs = new Hand(t_lhs.hand);
            lhs.sort();
            lhs.calcTotal();
            Hand rhs = new Hand(t_rhs.hand);
            rhs.sort();
            rhs.calcTotal();

            if(lhs.handTotal != rhs.handTotal)
                return lhs.handTotal > rhs.handTotal;
            //else, they are the same, check total value first
            if (lhs.highestCardValue != rhs.highestCardValue)
                return lhs.highestCardValue > rhs.highestCardValue;
            //else they are the same, and just check for the highest card
            for(int i = 0; i < 5; ++i)
            {
                if(lhs.hand[i].value != rhs.hand[i].value)
                    return lhs.hand[i].value > rhs.hand[i].value;
            }
            //we shouldn't make it this far....
            return false;
        }