Exemple #1
0
        public void AceLowStraight()
        {
            ThreeCardPokerGame game = new ThreeCardPokerGame();

            Player player1 = new Player("0");

            player1.TakeCard("8h");
            player1.TakeCard("Qh");
            player1.TakeCard("Kh");

            game.AddPlayer(player1);

            Player player2 = new Player("1");

            player2.TakeCard("3h");
            player2.TakeCard("As");
            player2.TakeCard("2d");

            game.AddPlayer(player2);

            Player player3 = new Player("2");

            player3.TakeCard("9d");
            player3.TakeCard("9s");
            player3.TakeCard("Kd");

            game.AddPlayer(player3);

            Assert.AreEqual(game.GetWinner(), "1");
        }
Exemple #2
0
        public void Pairs()
        {
            ThreeCardPokerGame game = new ThreeCardPokerGame();

            Player player1 = new Player("0");

            player1.TakeCard("Ac");
            player1.TakeCard("Kd");
            player1.TakeCard("Kh");

            game.AddPlayer(player1);

            Player player2 = new Player("1");

            player2.TakeCard("2h");
            player2.TakeCard("6c");
            player2.TakeCard("3h");

            game.AddPlayer(player2);

            Player player3 = new Player("2");

            player3.TakeCard("9d");
            player3.TakeCard("Ks");
            player3.TakeCard("Kc");

            game.AddPlayer(player3);

            Assert.AreEqual(game.GetWinner(), "0");
        }
Exemple #3
0
        public void Example1()
        {
            ThreeCardPokerGame game = new ThreeCardPokerGame();

            Player player1 = new Player("0");

            player1.TakeCard("2c");
            player1.TakeCard("As");
            player1.TakeCard("4d");

            game.AddPlayer(player1);

            Player player2 = new Player("1");

            player2.TakeCard("Kd");
            player2.TakeCard("5h");
            player2.TakeCard("6c");

            game.AddPlayer(player2);

            Player player3 = new Player("2");

            player3.TakeCard("Jc");
            player3.TakeCard("Jd");
            player3.TakeCard("9s");

            game.AddPlayer(player3);

            Assert.AreEqual(game.GetWinner(), "2");
        }
Exemple #4
0
        public void Example2_TieGame()
        {
            ThreeCardPokerGame game = new ThreeCardPokerGame();

            Player player1 = new Player("0");

            player1.TakeCard("Qc");
            player1.TakeCard("Kc");
            player1.TakeCard("4s");

            game.AddPlayer(player1);

            Player player2 = new Player("1");

            player2.TakeCard("Ah");
            player2.TakeCard("2c");
            player2.TakeCard("Js");

            game.AddPlayer(player2);

            Player player3 = new Player("2");

            player3.TakeCard("3h");
            player3.TakeCard("9h");
            player3.TakeCard("Th");

            game.AddPlayer(player3);

            Player player4 = new Player("3");

            player4.TakeCard("Tc");
            player4.TakeCard("9c");
            player4.TakeCard("3c");

            game.AddPlayer(player4);

            Assert.AreEqual(game.GetWinner(), "2 3");
        }
Exemple #5
0
        static void Main(string[] args)
        {
            int       playerCount = 0;
            const int maxPlayers  = 23;
            const int minPlayers  = 1;

            try
            {
                /* Create a new Game */
                ThreeCardPokerGame game = new ThreeCardPokerGame();

                /* Read the number of players */
                //Console.Write("Enter the number of players: ");
                string paramPlayerCount = Console.ReadLine();

                if (Int32.TryParse(paramPlayerCount, out playerCount))
                {
                    /* Player count is a valid integer */

                    /* Validate the number of players are withing acceptable range */
                    if ((playerCount < minPlayers) || (playerCount > maxPlayers))
                    {
                        throw new Exception("Invalid number of players!  Must be between " + minPlayers.ToString() + " and " + maxPlayers.ToString());
                    }
                    else
                    {
                        /* Read Player Data */
                        for (int counter = 0; counter < playerCount; counter++)
                        {
                            /* Get Player & Hand */

                            //Console.Write("Enter the Player ID and Hand for Player " + (counter + 1).ToString() + ": ");
                            string player_hand = Console.ReadLine();

                            /* Split input into component parts */
                            string[] components = player_hand.Split(" ");

                            /* Validate the number of components found */
                            if (components.Length != ThreeCardPokerGame.cardsPerHand + 1)
                            {
                                throw new Exception("Invalid input,  expected an integer, followed by " + ThreeCardPokerGame.cardsPerHand.ToString() + " strings, delimited by a space.");
                            }

                            if (!game.HasPlayer(components[0]))
                            {
                                /* Let's create a new player */
                                Player player = new Player(components[0]);
                                game.AddPlayer(player);

                                for (int idx = 1; idx <= ThreeCardPokerGame.cardsPerHand; idx++)
                                {
                                    /* Add card to player's hand */
                                    player.TakeCard(components[idx]);
                                }
                            }
                            else
                            {
                                throw new Exception("Player " + components[0] + " is already in the game!");
                            }
                        }

                        /* All Players and their Hands have been entered,  let's determine the winner */
                        Console.WriteLine(game.GetWinner());
                    }
                }
                else
                {
                    throw new Exception("Expected an integer representing the number of players!");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Exception: " + e.Message);
            }
        }