Ejemplo n.º 1
0
            public void Player1WinsWithStraight()
            {
                game = new PokerGame("name1", "name2");

                // Ignore the cards built by constructor for the test
                var p1 = new PokerPlayer("p1");
                var p2 = new PokerPlayer("p2");

                p1.Cards.Clear();
                p2.Cards.Clear();

                game.Player2.Cards.Clear();

                p1.Cards = new List<Card>
                {
                    new Card {Value = CardValue.Four, Suit = Suit.Diamonds},
                    new Card {Value = CardValue.Five, Suit = Suit.Hearts},
                    new Card {Value = CardValue.Seven, Suit = Suit.Spades},
                    new Card {Value = CardValue.Six, Suit = Suit.Clubs},
                    new Card {Value = CardValue.Three, Suit = Suit.Diamonds}
                };

                p2.Cards = new List<Card>
                {
                    new Card {Value = CardValue.Four, Suit = Suit.Diamonds},
                    new Card {Value = CardValue.Ace, Suit = Suit.Hearts},
                    new Card {Value = CardValue.Ten, Suit = Suit.Spades},
                    new Card {Value = CardValue.Two, Suit = Suit.Clubs},
                    new Card {Value = CardValue.King, Suit = Suit.Diamonds}
                };
            }
Ejemplo n.º 2
0
 public static OddsCalculator CreateFor(PokerGame game)
 {
     switch(game){
         case PokerGame.Holdem:
             return new HoldemOddsCalculator();
         default:
             return null;
     }
 }
        public bool AddToCurrentBet(PokerGame.Player player, int amount)
        {
            if (bets.ContainsKey(player))
            {
                PlaceABet(player, amount + bets[player]);
            }
            PlaceABet(player, amount);

            return true;
        }
Ejemplo n.º 4
0
 public static ColorMap Create(PokerGame game)
 {
     switch (game)
     {
         case PokerGame.Holdem:
             return new HoldemColorMap();
         default:
             Trace.Assert(false, "Cannot create color map object for " + game.ToString());
             return null;
     }
 }
Ejemplo n.º 5
0
        /* Factory method for creating new instances of player classes */
        public static Player CreatePlayer(String playerName, PokerGame gameType)
        {
            switch (gameType)
            {
                case PokerGame.Holdem:
                    return new HoldemPlayer(playerName);
            }

            Trace.Assert(false, "CreatePlayer was called for an unhandled game type");
            return null;
        }
Ejemplo n.º 6
0
        public void GameFactoryLoadedFileIsNotEmpty()
        {
            string[]  players  = { "Lucas", "Sixten" };
            string    fileName = "savedgame.txt";
            PokerGame game     = new PokerGame(players);

            game.SaveGame(fileName);

            var LoadGame = GameFactory.LoadGame(fileName);

            Assert.IsNotEmpty(LoadGame.Players);
        }
Ejemplo n.º 7
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.º 8
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.º 9
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.º 10
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.º 11
0
        public static ColorMap Create(PokerGame game)
        {
            switch (game)
            {
            case PokerGame.Holdem:
                return(new HoldemColorMap());

            default:
                Trace.Assert(false, "Cannot create color map object for " + game.ToString());
                return(null);
            }
        }
Ejemplo n.º 12
0
        public void PokerGameCanSaveToFile()
        {
            string[]  players  = { "Anna", "Petra" };
            string    fileName = "savedgame.txt";
            PokerGame game     = new PokerGame(players);

            game.SaveGame(fileName);
            string[] lines;

            lines = File.ReadAllLines(fileName);

            Assert.AreEqual("[\"Anna\",\"Petra\"] [0,0]", lines[0]);
        }
Ejemplo n.º 13
0
        public void PokerGame_Test_GameWinner()
        {
            List <Player> players = new List <Player>();

            players.Add(new Player("Mark"));
            players.Add(new Player("Jessie"));
            players.Add(new Player("Allison"));
            players.Add(new Player("Mahesh"));

            PokerGame testGame = new PokerGame(players);

            Assert.That(testGame.GameWinners, Is.Not.Null);
        }
Ejemplo n.º 14
0
            public void Player1WinsWithStraight()
            {
                game = new PokerGame("name1", "name2");

                // Ignore the cards built by constructor for the test
                var p1 = new PokerPlayer("p1");
                var p2 = new PokerPlayer("p2");

                p1.Cards.Clear();
                p2.Cards.Clear();

                game.Player2.Cards.Clear();

                p1.Cards = new List <Card>
                {
                    new Card {
                        Value = CardValue.Four, Suit = Suit.Diamonds
                    },
                    new Card {
                        Value = CardValue.Five, Suit = Suit.Hearts
                    },
                    new Card {
                        Value = CardValue.Seven, Suit = Suit.Spades
                    },
                    new Card {
                        Value = CardValue.Six, Suit = Suit.Clubs
                    },
                    new Card {
                        Value = CardValue.Three, Suit = Suit.Diamonds
                    }
                };

                p2.Cards = new List <Card>
                {
                    new Card {
                        Value = CardValue.Four, Suit = Suit.Diamonds
                    },
                    new Card {
                        Value = CardValue.Ace, Suit = Suit.Hearts
                    },
                    new Card {
                        Value = CardValue.Ten, Suit = Suit.Spades
                    },
                    new Card {
                        Value = CardValue.Two, Suit = Suit.Clubs
                    },
                    new Card {
                        Value = CardValue.King, Suit = Suit.Diamonds
                    }
                };
            }
Ejemplo n.º 15
0
        public void PokerGame_Test_Constructor()
        {
            List <Player> players = new List <Player>();

            players.Add(new Player("Mark"));
            players.Add(new Player("Jessie"));
            players.Add(new Player("Allison"));
            players.Add(new Player("Mahesh"));

            PokerGame testGame = new PokerGame(players);

            Assert.That(testGame.GamePlayers, Is.Not.Null);
            Assert.That(testGame.GamePlayers.Count, Is.EqualTo(4));
        }
Ejemplo n.º 16
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.º 17
0
        public void PokerGame_Test_Cards_Dealt()
        {
            int           expectedDeckSizeAfterDealing = 32;
            List <Player> players = new List <Player>();

            players.Add(new Player("Mark"));
            players.Add(new Player("Jessie"));
            players.Add(new Player("Allison"));
            players.Add(new Player("Mahesh"));

            PokerGame testGame = new PokerGame(players);

            Assert.That(testGame.GameDeck.DeckCount, Is.EqualTo(expectedDeckSizeAfterDealing));
        }
 public bool PlaceABet(PokerGame.Player player, int amount)
 {
     if (bets.ContainsKey(player))
     {
         if (amount <= bets[player])
         {
             LastErrorMessage = "New bet must be bigger than current";
             return false;
         }
         bets[player] = amount;
         return true;
     }
     bets.Add(player, amount);
     return true;
 }
Ejemplo n.º 19
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.º 20
0
        public static void Main(string[] args)
        {
            PokerGame aPokerGame = new PokerGame();

            aPokerGame.JoinPlayer("001", "Amy");
            aPokerGame.JoinPlayer("002", "Bob");

            aPokerGame.StartNewRound();
            aPokerGame.DealHandCards();
            aPokerGame.DealFlopCards();
            aPokerGame.DealTurnCard();
            aPokerGame.DealRiverCard();


            aPokerGame.DetermineWins();
        }
Ejemplo n.º 21
0
        public void PokerGame_RandomScenarioTest()
        {
            var poker = new PokerGame();

            poker.RegisterPlayer(new Player(1, "Don"));
            poker.RegisterPlayer(new Player(2, "Juan"));

            poker.StartGame();
            poker.Flop();
            poker.Turn();
            poker.River();
            poker.CheckPlayersHand();
            var winner = poker.ShowWinner();

            Assert.IsTrue(winner.Count > 0);
        }
        public int CompareTo(GameType other)
        {
            var gt  = (int)PokerGameType;
            var ogt = (int)other.PokerGameType;
            var co  = gt.CompareTo(ogt);

            if (co == 0)
            {
                co = PokerGame.CompareTo(other.PokerGame);
            }
            if (co == 0)
            {
                co = PokerGamePlayer.CompareTo(other.PokerGamePlayer);
            }
            return(co);
        }
Ejemplo n.º 23
0
        public void GameCanLoadAFile()
        {
            string[]  players  = { "Sven", "Per" };
            string    fileName = "savedgame.txt";
            PokerGame game     = new PokerGame(players);

            game.SaveGame(fileName);

            PokerGame LoadGame = new PokerGame(fileName);

            Assert.AreEqual(2, game.Players.Length);
            Assert.AreEqual("Sven", game.Players[0].Name);
            Assert.AreEqual(0, game.Players[0].Wins);
            Assert.AreEqual("Per", game.Players[1].Name);
            Assert.AreEqual(0, game.Players[1].Wins);
        }
Ejemplo n.º 24
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.º 25
0
        static void Main(string[] args)
        {
            var domainEvents = new Subject <IEvent>();

            EventReporter.WriteEventsToConsole(domainEvents);

            var eventBroker = new EventBroker(domainEvents);
            var prog        = new PokerGame(eventBroker);

            var bobBotClient     = new PokerClient.BotPokerClient(deck, eventBroker, "bob");
            var daveBotClient    = new PokerClient.BotPokerClient(deck, eventBroker, "dave");
            var realPlayerClient = new PokerClient(deck, eventBroker);

            while (true)
            {
                // dinada
            }
        }
Ejemplo n.º 26
0
        static void Main(string[] args)
        {
            Console.Title = "C# Poker Game v3";
            House.DisplayHouseRules();

            IDealer        dealer  = DealerFactory.CreateDealer();
            IPlayer        player1 = PlayerFactory.CreatePlayer(PlayerType.Computer);
            IPlayer        player2 = PlayerFactory.CreatePlayer(PlayerType.Human);
            List <IPlayer> players = new List <IPlayer>()
            {
                player1, player2
            };
            PokerGame pokerGame = PokerGameFactory.CreateGame(players, dealer);

            pokerGame.Start();

            Console.ReadLine();
        }
Ejemplo n.º 27
0
        public void testHighestCardInHand()
        {
            var p1 = new Player("Joe", new List <Card>()
            {
                new Card {
                    Rank = Rank.Jack, Suit = Suit.Heart
                },
                new Card {
                    Rank = Rank.Four, Suit = Suit.Diamond
                },
                new Card {
                    Rank = Rank.Nine, Suit = Suit.Clubs
                },
                new Card {
                    Rank = Rank.Nine, Suit = Suit.Diamond
                },
                new Card {
                    Rank = Rank.Queen, Suit = Suit.Heart
                }
            });                                                                                                       //create poker player
            var p2 = new Player("Gen", new List <Card>()
            {
                new Card {
                    Rank = Rank.Five, Suit = Suit.Clubs
                },
                new Card {
                    Rank = Rank.Seven, Suit = Suit.Diamond
                },
                new Card {
                    Rank = Rank.Nine, Suit = Suit.Heart
                },
                new Card {
                    Rank = Rank.Nine, Suit = Suit.Spades
                },
                new Card {
                    Rank = Rank.Queen, Suit = Suit.Spades
                }
            });

            PokerGame pg     = new PokerGame();
            var       result = pg.findPlayerWithHighCard(p1, p2);

            Assert.AreEqual(p1, result);
        }
Ejemplo n.º 28
0
        public PokerAi(PokerGame game)
        {
            _pokerGame      = game;
            _player         = game.Players[1]; // AI is always player 1
            _settings       = game.Settings;
            _actions        = GetActions(game);
            _dataController = new DataController(game.Settings.PlayerName);
            _round          = game.CurrentRound();
            _street         = game.Hand.Street.ToList();
            _hand           = game.Hand;

            if (game.Settings.EvaluationStyle == AiMode.MonteCarlo)
            {
                _monteCarloDecisionMaking = new MonteCarloDecisionMaking(_pokerGame);
            }
            else
            {
                _expectiMaxDecisionMaking = new ExpectiMaxDecisionMaking(_dataController.PlayerData);
            }
        }
Ejemplo n.º 29
0
        public void TestOnePlayerWinByHand()
        {
            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 should win because one pair

            pokerGame.AddPlayer(player2, player2Cards);

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

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

            CollectionAssert.AreEqual(winnerListFromPokerClass, expectedWinner);
        }
Ejemplo n.º 30
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.º 31
0
        public void PokerGame_Test_CheckHandValue_For_High_Card_2nd_attempt()
        {
            int                expectedResult = 5;
            List <Player>      players        = new List <Player>();
            List <PlayingCard> handTest       = new List <PlayingCard> {
                new PlayingCard(1, Suits.C), new PlayingCard(3, Suits.D), new PlayingCard(2, Suits.H), new PlayingCard(4, Suits.C), new PlayingCard(5, Suits.C)
            };
            Player mark = new Player("Mark");

            for (int i = 0; i < 5; i++)
            {
                mark.SetHand(handTest[i]);
            }

            players.Add(new Player("Jessie"));
            players.Add(new Player("Allison"));
            players.Add(new Player("Mahesh"));

            PokerGame testGame = new PokerGame(players);

            Assert.That(testGame.CheckHandValue(mark, 1), Is.EqualTo(expectedResult));
        }
Ejemplo n.º 32
0
        public void PokerGame_Test_CheckHand_For_One_Pair()
        {
            Hands              expectedResult = Hands.OnePair;
            List <Player>      players        = new List <Player>();
            List <PlayingCard> handTest       = new List <PlayingCard> {
                new PlayingCard(1, Suits.C), new PlayingCard(1, Suits.D), new PlayingCard(2, Suits.H), new PlayingCard(4, Suits.C), new PlayingCard(5, Suits.C)
            };
            Player mark = new Player("Mark");

            for (int i = 0; i < 5; i++)
            {
                mark.SetHand(handTest[i]);
            }

            players.Add(new Player("Jessie"));
            players.Add(new Player("Allison"));
            players.Add(new Player("Mahesh"));

            PokerGame testGame = new PokerGame(players);

            Assert.That(testGame.CheckHand(mark), Is.EqualTo(expectedResult));
        }
Ejemplo n.º 33
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.º 34
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.º 35
0
        public int CreateTable(CreateTableCommand c)
        {
            ListTables();

            m_LastUsedId++;
            while (m_Games.ContainsKey(m_LastUsedId))
            {
                m_LastUsedId++;
            }

            var game = new PokerGame(new PokerTable(c.Params));

            m_Games.Add(m_LastUsedId, game);

            var p = game.Table.Params;

            Logger.LogTableCreated(m_LastUsedId, p);
            Logger.LogGameCreated(m_LastUsedId);
            game.Start();

            return(m_LastUsedId);
        }
Ejemplo n.º 36
0
        public List <Player> GetAllPlayers()
        {
            try
            {
                PokerGame g     = GetPokerGameByID(1);
                var       lista = g.PokerTable.listPlayers.ToList();

                List <Player> l = new List <Player>();
                foreach (TexasHoldemPoker.Player p in lista)
                {
                    Player pl = new Player();
                    pl.Id      = p.Id;
                    pl.Name    = p.Name;
                    pl.Ammount = p.Amount;

                    l.Add(pl);
                }

                return(l);
            }
            catch (Exception ex)
            { return(null); }
        }
Ejemplo n.º 37
0
 public Bet(PokerGame.Player player, int amount)
 {
     Player = player;
     Amount = amount;
 }
 public int GetPlayersBetAmount(PokerGame.Player player)
 {
     return bets.Where(x => x.Key == player).Sum(x => x.Value);
 }
Ejemplo n.º 39
0
 public void Setup()
 {
     game = new PokerGame();
     comp = new PokerHandComparer(game);
 }
        public bool SplitThePotFor(PokerGame.Player player)
        {
            var potsWon = pots.Where(x => x.Holders.Contains(player)).ToList();
            pots = pots.Where(x => !x.Holders.Contains(player)).ToList();

            player.Wallet.Deposit(potsWon.Sum(x => x.Pot));

            return true;
        }
Ejemplo n.º 41
0
 public override void BeforeEachTest()
 {
     base.BeforeEachTest();
     game = new PokerGame();
 }
 public void ShouldAcceptACardForGetNameOnIGame()
 {
     var game = new PokerGame();
     var card = new Card(game) { Suit = "Spades", Value = "Ten" };
     game.GetName(card).ShouldBe("Ten of Spades");
 }