Exemplo n.º 1
0
        /// <summary>
        /// Takes the input of the players and Compares the values.
        /// </summary>
        /// <param name="hands"></param>
        /// <returns> Returns the winner of the game.</returns>
        public static string CalculateWinner(string hands)
        {
            string retval = string.Empty;

            try
            {
                PokerHands lefthand  = new PokerHands(hands.Substring(0, 14));
                PokerHands righthand = new PokerHands(hands.Substring(15));
                switch (lefthand.compareTo(righthand))
                {
                case 1:
                    retval = PokerConstants.LeftHandWins;
                    break;

                case -1:
                    retval = PokerConstants.RightHandWins;
                    break;

                case 0:
                    retval = PokerConstants.Draw;
                    break;
                }
            }
            catch (Exception ex)
            {
                retval = ex.Message;
            }

            return(retval);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Compares the left hand and right hand.
 /// </summary>
 /// <param name="righthand"></param>
 /// <returns>Returns 1 or -1 or 0</returns>
 public int compareTo(PokerHands righthand)
 {
     if (handcategory < righthand.handcategory)
     {
         return(1);
     }
     if (handcategory > righthand.handcategory)
     {
         return(-1);
     }
     if (handcategory == righthand.handcategory)
     {
         return(Cards.Max(c => c.Rank).CompareTo(righthand.Cards.Max(c => c.Rank)));
     }
     return(0);
 }