コード例 #1
0
 public Player()
 {
     playerHand          = new Card[5];
     sortedplayerHand    = new Card[5];
     playerHandevaluator = new HandEvaluator(sortedplayerHand);
     HandCount           = new Hand();
     ID = 0;
 }
コード例 #2
0
        private bool GreaterThan(Player a, Player b)
        {
            //create player's computer's evaluation objects (passing SORTED hand to constructor)
            HandEvaluator playera = new HandEvaluator(a.sortedplayerHand);
            HandEvaluator playerb = new HandEvaluator(b.sortedplayerHand);

            //get the player;s and computer's hand
            Hand playerAHand = playera.evaluatedHand();
            Hand playerBHand = playerb.evaluatedHand();



            if (playerAHand > playerBHand)
            {
                return(true);
            }
            else if (playerAHand < playerBHand)
            {
                return(false);
            }
            else //if the hands are the same, evaluate the values
            {
                //first evaluate who has higher value of poker hand
                if (playera.handValue.Total > playerb.handValue.Total)
                {
                    return(true);
                }
                else if (playera.handValue.Total < playerb.handValue.Total)
                {
                    return(false);
                }
                //if both hanve the same poker hand (for example, both have a pair of queens),
                //than the player with the next higher card wins
                else if (playera.handValue.HighCard > playerb.handValue.HighCard)
                {
                    return(true);
                }
                else if (playera.handValue.HighCard < playerb.handValue.HighCard)
                {
                    return(false);
                }
                else
                {
                    Console.WriteLine("DRAW, no one wins!");
                }
            }
            return(false);
        }