Ejemplo n.º 1
0
        public void TestManyPlayersOneWinner()
        {
            PokerGame pokerGame    = new PokerGame();
            string    player1      = "Tester1";
            string    player1Cards = "2h 6d as 4s 3h"; //this is high card only

            pokerGame.AddPlayer(player1, player1Cards);

            string player2      = "Tester2";
            string player2Cards = "2s 2d 5d 4c 3d"; //this is one pair

            pokerGame.AddPlayer(player2, player2Cards);

            string player3      = "Tester3";
            string player3Cards = "2c 3c 5h 5c 3s"; //this should win because two pair

            pokerGame.AddPlayer(player3, player3Cards);

            pokerGame.StartGame();
            List <string> expectedWinner = new List <string>();

            expectedWinner.Add(player3);
            List <string> winnerListFromPokerClass = pokerGame.GetWinners();

            CollectionAssert.AreEqual(winnerListFromPokerClass, expectedWinner);
        }
Ejemplo n.º 2
0
        public void TestManyPlayerWithManyWinners()
        {
            PokerGame pokerGame    = new PokerGame();
            string    player1      = "Tester1";
            string    player1Cards = "10h 6d as 4s 9h"; //this is high card

            pokerGame.AddPlayer(player1, player1Cards);

            string player2      = "Tester2";
            string player2Cards = "10s 6h ad 4c 9d"; //this is also high card but similar to 1

            pokerGame.AddPlayer(player2, player2Cards);

            string player3      = "Tester3";
            string player3Cards = "2c 4d 5h 3c 7s"; //this is also high card

            pokerGame.AddPlayer(player3, player3Cards);

            pokerGame.StartGame();
            List <string> expectedWinner = new List <string>();

            expectedWinner.Add(player1);
            expectedWinner.Add(player2);
            List <string> winnerListFromPokerClass = pokerGame.GetWinners();

            CollectionAssert.AreEqual(winnerListFromPokerClass, expectedWinner);
        }
Ejemplo n.º 3
0
        public HttpResponseMessage GetWinner(GameViewModel game)
        {
            string message = "Error: ";
            HttpResponseMessage resp;

            if (game != null && game.Hand1 != null && game.Hand2 != null)
            {
                try
                {
                    PokerGame pokergame = new PokerGame();
                    pokergame.AddPlayer(new Player(game.Hand1.playername, game.Hand1.c1, game.Hand1.c2, game.Hand1.c3, game.Hand1.c4, game.Hand1.c5));
                    pokergame.AddPlayer(new Player(game.Hand2.playername, game.Hand2.c1, game.Hand2.c2, game.Hand2.c3, game.Hand2.c4, game.Hand2.c5));

                    message = pokergame.GetWinner();
                    resp    = Request.CreateResponse(HttpStatusCode.OK);
                }
                catch (Exception ex)
                {
                    message += ex.Message;
                    resp     = Request.CreateErrorResponse(HttpStatusCode.BadRequest, message);
                }
            }
            else
            {
                message += "Player game or hands not provided.";
                resp     = Request.CreateErrorResponse(HttpStatusCode.BadRequest, message);
            }

            resp.Content = new StringContent(message, System.Text.Encoding.Unicode);

            return(resp);
        }
Ejemplo n.º 4
0
        public void TestFlushBeatsStraight()
        {
            PokerGame pokergame = new PokerGame();

            pokergame.AddPlayer(new Player("p1", "2H", "4h", "5h", "8h", "kh"));
            pokergame.AddPlayer(new Player("p2", "4c", "6h", "8d", "7s", "5s"));

            string winner = pokergame.GetWinner();

            Assert.AreEqual(winner, "p1");
        }
Ejemplo n.º 5
0
        public void TestFOAKBeatsFullHouse()
        {
            PokerGame pokergame = new PokerGame();

            pokergame.AddPlayer(new Player("p1", "ah", "as", "ac", "2h", "2d"));
            pokergame.AddPlayer(new Player("p2", "4c", "4d", "4s", "7s", "4h"));

            string winner = pokergame.GetWinner();

            Assert.AreEqual(winner, "p2");
        }
Ejemplo n.º 6
0
        public void TestTieGame()
        {
            PokerGame pokergame = new PokerGame();

            pokergame.AddPlayer(new Player("p1", "2H", "4h", "5s", "8d", "kc"));
            pokergame.AddPlayer(new Player("p2", "4c", "jc", "8d", "ks", "5s"));

            string winner = pokergame.GetWinner();

            Assert.AreEqual(winner, "Tie");
        }
Ejemplo n.º 7
0
        public void TestAddPlayersToGame()
        {
            PokerGame pokergame = new PokerGame();

            pokergame.AddPlayer(new Player("p1", "2H", "4h", "5h", "8h", "kh"));

            Assert.AreEqual(pokergame.Players[0].Name, "p1");
            Assert.AreEqual(pokergame.NumPlayers, 1);

            pokergame.AddPlayer(new Player("p2", "4c", "6h", "8d", "7s", "5s"));
            Assert.AreEqual(pokergame.NumPlayers, 2);
        }
Ejemplo n.º 8
0
        private void setNewGame()
        {
            try
            {
                objBetterHandPlayer = null;
                lblYourRanking.ResetText();
                lblComRanking.ResetText();

                pnlYou.Controls.Clear();
                pnlCom.Controls.Clear();


                objPokerGame = new PokerGame();

                objPokerGame.BettingDone         += Player_BettingDone;
                objPokerGame.FoldDone            += objPokerGame_FoldDone;
                objPokerGame.BettingTurnFinished += objPokerGame_BettingTurnFinished;
                objPokerGame.GameEnd             += objPokerGame_GameEnd;
                objPokerGame.PuAnteFailed        += objPokerGame_PuAnteFailed;

                objPlayerYou.NoMoreMoney += Player_NoMoreMoney;
                objPlayerCom.NoMoreMoney += Player_NoMoreMoney;

                objPokerGame.AddPlayer(objPlayerYou);
                objPokerGame.AddPlayer(objPlayerCom);

                ShowPlayerImages();
                SetControls(false);

                foreach (Player player in objPokerGame.Players)
                {
                    objPokerGame.PutAnte(player);
                }

                foreach (Player player in objPokerGame.Players)
                {
                    Card theCard = objPokerGame.Deck.DrawOneCard();
                    theCard.ChangeStatus(Status.FaceDown);
                    player.Hand.AddCard(theCard);
                }
                ShowCard(pnlYou, objPlayerYou.Hand, objPlayerYou.Hand.Count - 1);
                ShowCard(pnlCom, objPlayerCom.Hand, objPlayerCom.Hand.Count - 1);

                DrawACardToEachPlayers();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 9
0
        public void TestPlayersHasMoreCardsThanRequired()
        {
            PokerGame pokerGame    = new PokerGame();
            string    player1      = "Tester1";
            string    player1Cards = "2h 2c as 4s 3h ah ad"; //this is high card but should win

            pokerGame.AddPlayer(player1, player1Cards);

            string player2      = "Tester2";
            string player2Cards = "2d 2s kh 4h 3d 5d 6d 7d"; //this is high card

            pokerGame.AddPlayer(player2, player2Cards);

            pokerGame.StartGame();
            List <string> expectedWinner = new List <string>();

            expectedWinner.Add(player1);
            List <string> winnerListFromPokerClass = pokerGame.GetWinners();

            CollectionAssert.AreEqual(winnerListFromPokerClass, expectedWinner);
        }
Ejemplo n.º 10
0
        public void TestOnePairHand()
        {
            PokerGame pokerGame  = new PokerGame();
            string    playerName = "Test";
            string    playerCard = "2h 4d as 4s 3h";

            pokerGame.AddPlayer(playerName, playerCard);
            pokerGame.StartGame();
            string targetValue = CardHand.OnePair.ToString();

            Assert.IsTrue(pokerGame.GetPlayerHand(0).Equals(targetValue));
        }
Ejemplo n.º 11
0
        public void TestThreeofAKindHand()
        {
            PokerGame pokerGame  = new PokerGame();
            string    playerName = "Test";
            string    playerCard = "2h 6d as 2s 2d";

            pokerGame.AddPlayer(playerName, playerCard);
            pokerGame.StartGame();
            string targetValue = CardHand.ThreeOfAKind.ToString();

            Assert.IsTrue(pokerGame.GetPlayerHand(0).Equals(targetValue));
        }
Ejemplo n.º 12
0
        public void TestStraightHand()
        {
            PokerGame pokerGame  = new PokerGame();
            string    playerName = "Test";
            string    playerCard = "4h 3d 2s 6s 5h";

            pokerGame.AddPlayer(playerName, playerCard);
            pokerGame.StartGame();
            string targetValue = CardHand.Straight.ToString();

            Assert.IsTrue(pokerGame.GetPlayerHand(0).Equals(targetValue));
        }
Ejemplo n.º 13
0
        public void TestFlushHand()
        {
            PokerGame pokerGame  = new PokerGame();
            string    playerName = "Test";
            string    playerCard = "2h 6h ah 4h 3h";

            pokerGame.AddPlayer(playerName, playerCard);
            pokerGame.StartGame();
            string targetValue = CardHand.Flush.ToString();

            Assert.IsTrue(pokerGame.GetPlayerHand(0).Equals(targetValue));
        }
Ejemplo n.º 14
0
        public void TestBothPlayerWinSameHand()
        {
            PokerGame pokerGame    = new PokerGame();
            string    player1      = "Tester1";
            string    player1Cards = "2h 6d as 4s 3h"; //this is high card

            pokerGame.AddPlayer(player1, player1Cards);

            string player2      = "Tester2";
            string player2Cards = "2d 6c ah 4h 3d"; //also high card but both should win

            pokerGame.AddPlayer(player2, player2Cards);

            pokerGame.StartGame();
            List <string> expectedWinner = new List <string>();

            expectedWinner.Add(player1);
            expectedWinner.Add(player2);
            List <string> winnerListFromPokerClass = pokerGame.GetWinners();

            CollectionAssert.AreEqual(winnerListFromPokerClass, expectedWinner);
        }
Ejemplo n.º 15
0
        public CommandReplay RegisterPlayerToGame(Player customer)
        {
            TexasHoldemPoker.Player p = new TexasHoldemPoker.Player(customer.Name);
            p.Id     = customer.Id;
            p.Name   = customer.Name;
            p.Amount = customer.Ammount;

            playerStreamlist.Add(customer.Id, new PlayerStream(p));

            PokerGame pokerGame = _gameProvider.GetPokerGameByID(1);

            pokerGame.AddPlayer(p);

            return(GenerateCommandReplay(PokerCommand.NewPlayer));
        }
Ejemplo n.º 16
0
        static void Main(string[] args)
        {
            CardValidator cardValidator          = new CardValidator();
            PokerGame     pokerGame              = new PokerGame();
            bool          isTerminated           = false;
            int           currentNumberOfPlayers = 0;

            ShowIntroductions();
            while (!isTerminated)
            {
                Console.Write("\nEnter the player name: ");
                string playerName = Console.ReadLine();
                string playerCard = string.Empty;
                DeclarePlayerCard(playerName, ref playerCard);
                while (cardValidator.IsValid(playerCard, out string errorMessage) != true)
                {
                    Console.WriteLine("Error: {0}\n", errorMessage);
                    DeclarePlayerCard(playerName, ref playerCard);
                }
                pokerGame.AddPlayer(playerName, playerCard);
                currentNumberOfPlayers++;
                if (currentNumberOfPlayers > 1)
                {
                    Console.WriteLine("\nPress ANY KEY to add more players or ESC to start\n");
                    if (Console.ReadKey(true).Key == ConsoleKey.Escape)
                    {
                        isTerminated = true;
                    }
                }
            }
            pokerGame.StartGame();
            Console.WriteLine("-------Results-------");
            for (int i = 0; i < pokerGame.NumberOfPlayers; i++)
            {
                Console.WriteLine("{0}: {1} ({2})", pokerGame.GetPlayerName(i),
                                  pokerGame.GetCardCollection(i), pokerGame.GetPlayerHand(i));
            }
            Console.WriteLine("\n-------Winner/s-------");
            for (int i = 0; i < pokerGame.GetWinners().Count; i++)
            {
                Console.WriteLine(pokerGame.GetWinners()[i]);
            }
            Console.WriteLine("\nPress ANY KEY to exit");
            Console.ReadLine();
        }
Ejemplo n.º 17
0
        public void PokerGame_CheckingCardsInDeckPerPull()
        {
            var pokerGame = new PokerGame();

            var players = new List <PokerPlayer>()
            {
                new PokerPlayer()
                {
                    Name = "Marvz"
                },
                new PokerPlayer()
                {
                    Name = "Keng"
                },
                new PokerPlayer()
                {
                    Name = "Des"
                },
                new PokerPlayer()
                {
                    Name = "Joel"
                },
                new PokerPlayer()
                {
                    Name = "Wash"
                }
            };

            foreach (var player in players)
            {
                pokerGame.AddPlayer(player);
            }

            pokerGame.Start();

            int expectedRemainingCards = 52 - (players.Count * 5);

            Assert.AreEqual(expectedRemainingCards, pokerGame.Deck.Cards.Count);
        }
Ejemplo n.º 18
0
        static void Main(string[] args)
        {
            var answer    = string.Empty;
            var pokerGame = new PokerGame();

            while (true)
            {
                Console.Clear();
                pokerGame.Reset();
                Console.WriteLine(string.Format("Let's play {0}!", pokerGame.Name));
                Console.WriteLine("\nFilling up the Deck...");
                Console.WriteLine("\nShuffling Cards...");
                Console.WriteLine(string.Format("\nInitial no. of cards in the deck: {0}", pokerGame.Deck.Cards.Count()));

                Console.WriteLine("\nInitializing Players...");
                var players = new List <PokerPlayer>()
                {
                    new PokerPlayer()
                    {
                        Name = "Marvz"
                    },
                    new PokerPlayer()
                    {
                        Name = "Keng"
                    },
                    new PokerPlayer()
                    {
                        Name = "Des"
                    },
                    new PokerPlayer()
                    {
                        Name = "Joel"
                    },
                    new PokerPlayer()
                    {
                        Name = "Wash"
                    }
                };

                foreach (var player in players)
                {
                    pokerGame.AddPlayer(player);
                }

                Console.WriteLine("\nGame Start!!!");
                pokerGame.Start();

                Console.WriteLine("\nPlayers! Show Hand!\n");

                foreach (var player in pokerGame.Players)
                {
                    var cardCodeList = new List <string>();

                    foreach (var card in player.Hand.Cards)
                    {
                        cardCodeList.Add(card.Code);
                    }

                    Console.WriteLine(string.Format("{0}: {1} ({2})", player.Name, string.Join(", ", cardCodeList), player.Hand.HandCategory.ToString()));
                }

                Console.WriteLine("\nTotal remaining cards in the deck: " + pokerGame.Deck.Cards.Count());
                Console.WriteLine("\nEvaluating Winner(s)...");

                var winnerList = new List <string>();
                foreach (var winner in pokerGame.Winners)
                {
                    winnerList.Add(winner.Name);
                }

                Console.WriteLine(string.Format("\nWinner(s)!: {0} ({1})", string.Join(", ", winnerList).ToString(), pokerGame.WinnersHandCategory));
                Console.Write("\nDo you want to play again? (Y/N):");

                while (true)
                {
                    answer = Console.ReadLine();
                    if (answer.ToLower().Equals("y") || answer.ToLower().Equals("n"))
                    {
                        break;
                    }

                    Console.WriteLine("Error invalid entry");
                    Console.Write("\nDo you want to play again? (Y/N):");
                }

                if (answer.ToLower().Equals("n"))
                {
                    break;
                }
            }
        }