Exemplo n.º 1
0
        public void EvaluateHands()
        {
            //create player's computer's evaluation object(passing SORTED hand to Constructor)
            HandEvaluator playerHandEvaluator   = new HandEvaluator(sortedPlayerHand);
            HandEvaluator computerHandEvaluator = new HandEvaluator(sortedComputerHand);

            //get the player's and computer'hand
            Hand playerHand   = playerHandEvaluator.EvaluateHand();
            Hand computerHand = computerHandEvaluator.EvaluateHand();

            //display each hand
            Console.WriteLine("\n\n\n\nPlayer's Hand: " + playerHand);
            Console.WriteLine("\nComputer's Hand: " + computerHand);

            //evaluate hands
            if (playerHand > computerHand)
            {
                Console.WriteLine("Player WINS!");
            }
            else if (playerHand < computerHand)
            {
                Console.WriteLine("Computer WINS!");
            }
            else // if the hands are the same , evaluate the values
            {
                //first evaluate who has higher value of poker hand
                if (playerHandEvaluator.HandValues.Total > computerHandEvaluator.HandValues.Total)
                {
                    Console.WriteLine("Player WINS!");
                }
                else if (playerHandEvaluator.HandValues.Total < computerHandEvaluator.HandValues.Total)
                {
                    Console.WriteLine("Computer WINS!");
                }
                // if both have the same poker hand (for example both have a pair of queens),
                //then the player with the next higher card wins
                else if (playerHandEvaluator.HandValues.HighCard > computerHandEvaluator.HandValues.HighCard)
                {
                    Console.WriteLine("Player WINS!");
                }
                else if (playerHandEvaluator.HandValues.HighCard < computerHandEvaluator.HandValues.HighCard)
                {
                    Console.WriteLine("Computer WINS!");
                }
                else
                {
                    Console.WriteLine("DRAW!!!, no one wins!");
                }
            }
        }
Exemplo n.º 2
0
        private void EvaluateWinnigHand()
        {
            HandEvaluator playerHandEvaluator   = new HandEvaluator(sortedPlayerHand);
            HandEvaluator computerHandEvaluator = new HandEvaluator(sortedComputerHand);

            //get the player;s and computer's hand
            HandType playerHand   = playerHandEvaluator.EvaluateHand();
            HandType computerHand = computerHandEvaluator.EvaluateHand();

            //display each hand
            Console.WriteLine("\n\n\n\n\nPlayer's Hand: " + playerHand);
            Console.WriteLine("\nComputer's Hand: " + computerHand);

            //evaluate hands
            if (playerHand > computerHand)
            {
                Console.WriteLine("Player WINS!");
            }
            else if (playerHand < computerHand)
            {
                Console.WriteLine("Computer WINS!");
            }
            else //if the hands are the same, evaluate the values
            {
                //first evaluate who has higher value of poker hand
                if (playerHandEvaluator.HandValue.TotalValue > computerHandEvaluator.HandValue.TotalValue)
                {
                    Console.WriteLine("Player WINS!");
                }
                else if (playerHandEvaluator.HandValue.TotalValue < computerHandEvaluator.HandValue.TotalValue)
                {
                    Console.WriteLine("Computer WINS!");
                }
                //if both have the same poker hand (for example, both have a pair of queens),
                //than the player with the next higher card wins
                else if (playerHandEvaluator.HandValue.HighCardValue > computerHandEvaluator.HandValue.HighCardValue)
                {
                    Console.WriteLine("Player WINS!");
                }
                else if (playerHandEvaluator.HandValue.HighCardValue < computerHandEvaluator.HandValue.HighCardValue)
                {
                    Console.WriteLine("Computer WINS!");
                }
                else
                {
                    Console.WriteLine("DRAW, no one wins!");
                }
            }
        }
Exemplo n.º 3
0
        public void EvaluateHands()
        {
            Console.ForegroundColor = ConsoleColor.White;

            HandEvaluator playerHandEval = new HandEvaluator(sortedPlayerHand);
            HandEvaluator cpuHandEval    = new HandEvaluator(sortedCpuHand);

            Hand playerHand = playerHandEval.EvaluateHand();
            Hand cpuHand    = cpuHandEval.EvaluateHand();

            Console.WriteLine("\n\nPlayer's Hand: " + playerHand);
            Console.WriteLine("CPU's Hand: " + cpuHand);

            if (playerHand > cpuHand)
            {
                Console.WriteLine("Player wins!");
            }
            else if (playerHand < cpuHand)
            {
                Console.WriteLine("Computer wins!");
            }
            else
            {
                if (playerHandEval.HandValues.Total > cpuHandEval.HandValues.Total)
                {
                    Console.WriteLine("Player wins!");
                }
                else if (playerHandEval.HandValues.Total < cpuHandEval.HandValues.Total)
                {
                    Console.WriteLine("Computer wins!");
                }
                else if (playerHandEval.HandValues.HighCard > cpuHandEval.HandValues.HighCard)
                {
                    Console.WriteLine("Player wins!");
                }
                else if (playerHandEval.HandValues.HighCard < cpuHandEval.HandValues.HighCard)
                {
                    Console.WriteLine("Computer wins!");
                }
                else
                {
                    Console.WriteLine("Draw!");
                }
            }

            Console.WriteLine();
        }
Exemplo n.º 4
0
        private void EvaluateHands()
        {
            HandEvaluator playerHandEvaluator = new HandEvaluator(sortedPlayerHand);
            HandEvaluator computerHandEvaluator = new HandEvaluator(sortedComputerHand);

            Hand playerHand = playerHandEvaluator.EvaluateHand();
            Hand computerHand = computerHandEvaluator.EvaluateHand();

            Console.WriteLine("\n\n\n\n\nPlayer's Hand: " + playerHand);
            Console.WriteLine("\nComputer's Hand: " + computerHand);

            if (playerHand > computerHand)
            {
                Console.WriteLine("Player WINS!");
                playerWins++;
            }
            else if (playerHand < computerHand)
            {
                Console.WriteLine("Computer WINS!");
                computerWins++;
            }
            else
            {
                if (playerHandEvaluator.HandValues.Total > computerHandEvaluator.HandValues.Total)
                {
                    Console.WriteLine("Player WINS!");
                    playerWins++;
                }
                else if (playerHandEvaluator.HandValues.Total < computerHandEvaluator.HandValues.Total)
                {
                    Console.WriteLine("Computer WINS!");
                    computerWins++;
                }
                else if (playerHandEvaluator.HandValues.HighCard > computerHandEvaluator.HandValues.HighCard)
                {
                    Console.WriteLine("Player WINS!");
                    playerWins++;
                }
                else if (playerHandEvaluator.HandValues.HighCard < computerHandEvaluator.HandValues.HighCard)
                {
                    Console.WriteLine("Computer WINS!");
                    computerWins++;
                }
                else
                    Console.WriteLine("DRAW, no one wins!");
            }
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            Player player1             = new Player();
            Player player2             = new Player();
            int    player1NumberOfWins = 0;
            int    player2NumberOfWins = 0;
            int    gameCounter         = 0;
            string filePath            = @"C:\Users\nichj\OneDrive\Documents\Visual Studio 2015\Projects\PokerGame\poker.txt";


            Dealer dealer = new Dealer(filePath);

            dealer.DealCards();
            List <Game> games = dealer.Games;

            foreach (Game game in games)
            {
                HandEvaluator evaluator     = new HandEvaluator(game);
                string        gameResultMsg = string.Empty;
                StringBuilder sb            = new StringBuilder();

                evaluator.EvaluateGame(game);
                player1 = game.Player1;
                player2 = game.Player2;

                if (player1.IsWinner)
                {
                    player1NumberOfWins++;
                    gameResultMsg = string.Format("Winner: Player1 - {0}", player1.HandPlayed.Type);
                }
                else if (player2.IsWinner)
                {
                    player2NumberOfWins++;
                    gameResultMsg = string.Format("Winner: Player2 - {0}", player2.HandPlayed.Type);
                }

                foreach (var card in game.Player1.HandDealt.Cards)
                {
                    sb.AppendFormat("{0}{1} ", card.Number, card.Suit);
                }

                sb.Append("| ");

                foreach (var card in game.Player2.HandDealt.Cards)
                {
                    sb.AppendFormat("{0}{1} ", card.Number, card.Suit);
                }

                sb.AppendFormat(" =>  {0} ", gameResultMsg);

                Console.WriteLine(sb.ToString());
                Console.Write("");

                gameCounter++;
            }

            Console.WriteLine("Number of games played: " + gameCounter.ToString());
            Console.WriteLine(string.Format("Total Player 1 wins: {0}", player1NumberOfWins.ToString()));
            Console.WriteLine(string.Format("Total Player 2 wins: {0}", player2NumberOfWins.ToString()));
            Console.ReadKey();
        }