Exemplo n.º 1
0
        /// <summary>
        /// Perform a raise, call or fold, based on non-user player's situation in game.
        /// </summary>
        /// <returns></returns>
        static private void makeMoveComputer(Player player)
        {
            // The player is going bankrupt.
            if (player.GetMoney() <= currentBid)
            {
                Console.WriteLine($"{player.Name} bets ${player.GetMoney()}.");
                moneyPool += player.PayEntryFee(player.GetMoney());
            }

            // The player is making a normal move.
            else
            {
                int bidRaise = 0;
                if (new Random().NextDouble() <= foldProbability(player, currentBid))
                {
                    player.Fold();
                }
                else if (new Random().NextDouble() < raiseProbability(player, currentBid))
                {
                    bidRaise = player.Raise(currentBid);
                }
                else
                {
                    player.Call(currentBid);
                }

                currentBid += bidRaise;
                moneyPool  += currentBid;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Compute the probability of folding for non-user players.
        /// </summary>
        /// <returns>Returns the probability of folding the hand.</returns>
        static private double foldProbability(Player player, int currentBid)
        {
            double probability;

            // Players with at least a pair of cards will rarely fold. Unless scared by the bid.
            if (!player.GetRank().ContainsKey(Rank.HighCard))
            {
                int playerRank = (int)player.GetRank().First().Key + 3;
                probability = (0.1 / playerRank) + (currentBid / player.GetMoney() / 2);
            }
            else
            {
                // Players with 2 or 3 as a first card are most likely to fold.
                // The probability of folding decreases with the amount of cards.
                int highCardValue = (int)player.GetRank()[Rank.HighCard][0].Value + 1;
                probability = Math.Pow(Math.Log(14 - highCardValue, 14), 15 + 10 * player.Aggressiveness);
            }

            return(probability);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Choose to raise the bid, call or fold.
        /// </summary>
        static private void makeMoveUser(Player player)
        {
            // The player is going bankrupt.
            if (player.GetMoney() <= currentBid)
            {
                Console.WriteLine($"Bet ${player.GetMoney()}.");
                Console.ReadKey(true);
                ConsoleEditor.ClearLastLines(1);
                Console.WriteLine($"{player.Name} bets ${player.GetMoney()}.");
                moneyPool += player.PayEntryFee(player.GetMoney());
            }

            // The player is making a normal move.
            else
            {
                int  bidRaise = 0;
                bool repeat   = true;
                // No one raised the bid.
                if (currentBid == 0)
                {
                    while (repeat)
                    {
                        Console.WriteLine("[B] Bet\n[C] Check\n[F] Fold\n");
                        var key = Console.ReadKey(true).Key;
                        ConsoleEditor.ClearLastLines(4);
                        switch (key)
                        {
                        // A bet is a raise, when the bid is 0.
                        case ConsoleKey.B:
                            bidRaise    = player.Raise(currentBid);
                            currentBid += bidRaise;
                            moneyPool  += currentBid;
                            repeat      = false;
                            break;

                        // A check is a call, when the bid is 0.
                        case ConsoleKey.C:
                            player.Call(currentBid);
                            repeat = false;
                            break;

                        case ConsoleKey.F:
                            player.Fold();
                            repeat = false;
                            break;
                        }
                    }
                }
                // The bid is already raised.
                else
                {
                    while (repeat)
                    {
                        Console.WriteLine("[C] Call\n[R] Raise\n[F] Fold\n");
                        var key = Console.ReadKey(true).Key;
                        ConsoleEditor.ClearLastLines(4);
                        switch (key)
                        {
                        case ConsoleKey.C:
                            player.Call(currentBid);
                            moneyPool += currentBid;
                            repeat     = false;
                            break;

                        case ConsoleKey.R:
                            bidRaise    = player.Raise(currentBid);
                            currentBid += bidRaise;
                            moneyPool  += currentBid;
                            repeat      = false;
                            break;

                        case ConsoleKey.F:
                            player.Fold();
                            repeat = false;
                            break;
                        }
                    }
                }
            }
        }