private static void OutputWinnerInfo(Player winner, Player loser)
 {
     Console.WriteLine("{0} beat {1}.\nThe winning hand was a {2} that consisted of:\n{3}\n\nThe losing hand was a {4} consisting of:\n{5}",
         winner.Name, loser.Name, winner.HandName, winner.PrintHand(), loser.HandName, loser.PrintHand());
     Console.WriteLine("Press any key to quit.");
     Console.ReadKey();
 }
 private static void OutputTie(Player player1, Player player2)
 {
     Console.WriteLine("{0} and {1} tied. They both drew a {2} with a high card of {3}.", player1.Name, player2.Name, player1.HandName, player1.HighCard);
     Console.WriteLine("{0}'s hand was:\n{1}\n\n{2}'s hand was:\n{4}", player1.Name, player1.PrintHand(), player2.Name, player2.PrintHand());
     Console.WriteLine("Press any key to quit.");
     Console.ReadKey();
 }
        public static Player DetermineWinner(Player player1, Player player2)
        {
            Player winner;
            player1.HandPointValue = GetHandType(player1.Hand);
            player2.HandPointValue = GetHandType(player2.Hand);
            player1.HandName = GetHandName(player1.HandPointValue);
            player2.HandName = GetHandName(player2.HandPointValue);

            // Player 1 wins by points
            if (player1.HandPointValue > player2.HandPointValue)
                winner = player1;

            //Points are tied
            else if (player1.HandPointValue == player2.HandPointValue)
                // P1 high card
                if (player1.Hand.Cards[0].Value > player2.Hand.Cards[0].Value)
                    winner = player1;
                // Point and high card tie
                else if (player1.Hand.Cards[0].Value > player2.Hand.Cards[0].Value)
                    winner = null;
                //P2 high card
                else
                    winner = player2;
            // P2 point win.
            else
                winner = player2;
            return winner;
        }
        public static Player DetermineWinner(Player player1, Player player2)
        {
            var player1Points = (int)player1.HandType;
            var player2Points = (int)player2.HandType;
            Player winner;

            // Player 1 wins by points
            if (player1Points > player2Points)
                winner = player1;

            //Points are tied
            else if (player1Points == player2Points)
                // P1 high card
                if (player1.HighCard.Value > player2.HighCard.Value)
                    winner = player1;
                // Point and high card tie
                else if (player1.HighCard.Value == player2.HighCard.Value)
                    winner = null;
                //P2 high card
                else
                    winner = player2;
            // P2 point win.
            else
                winner = player2;
            return winner;
        }
 private static void Main(string[] args)
 {
     var player1 = new Player("Chris");
     var player2 = new Player("Corey");
     var deck = new Deck();
     player1.DrawNewHand(deck);
     player2.DrawNewHand(deck);
     Player winner = HandEvaluator.DetermineWinner(player1, player2);
     if (winner != null) {
         Player loser = (winner == player1) ? player2 : player1;
         OutputWinnerInfo(winner, loser);
     }
     else
         OutputTie(player1, player2);
 }
 public void EnsurePlayerNameCannotBeNull()
 {
     var player = new Player(name: null);
 }
 public void EnsurePlayerNameCannotBeEmpty()
 {
     var player = new Player(string.Empty);
 }
 /*
  * 1. Check three different combinations of hands to ensure that the winner and loser are being properly
       identified.
  * 2. Check to ensure that ties can be properly detected.
  */
 public static void TestDetermineWinner()
 {
     var flush = new Player("Winner", flushHand);
     var highCardPlayer = new Player("Loser", highCard);
     Debug.Assert((flush.Equals(HandEvaluator.DetermineWinner(flush, highCardPlayer))), "Victory Error", "Determine winner failed to properly identify a winner");
     Debug.Assert((null == HandEvaluator.DetermineWinner(highCardPlayer, highCardPlayer)));
 }
        public void TestDeterminingWinners()
        {
            var fourOfAKindHighCard = new Player(FourOfAKindHighCard);
            var fourOfAKindLowCard = new Player(FourOfAKindLowCard);
            var twoPair = new Player(TwoPair);
            var lowCardTie = new Player(FourOfAKindLowCard);

            // Check for standard win.
            Assert.AreSame(fourOfAKindHighCard, HandEvaluator.DetermineWinner(fourOfAKindHighCard, twoPair), "Winner Error", "Improperly evaluated a winner based on points.");
            Assert.AreSame(fourOfAKindHighCard, HandEvaluator.DetermineWinner(fourOfAKindHighCard, fourOfAKindLowCard), "Winner Error", "Improperly evaluated the winner of a point tie using the high card");
            Assert.IsNull(HandEvaluator.DetermineWinner(fourOfAKindLowCard, lowCardTie), "Winner Error", "Failed to detect a tie in both points and high card");
        }