Exemple #1
0
        /// <summary>
        /// Player chooses the amount of money they want to bet in the current turn.
        /// </summary>
        /// <returns>Returns the amount by which the players raises the bid.</returns>
        public int Raise(int currentBid)
        {
            // What is the value of the new bid.
            int newBid;

            // The user takes turn.
            if (isUser)
            {
                // First bet should be at least $100. Next bid should be a least $10 more.
                int lowerBound = Math.Max(currentBid - (currentBid % 10) + 10, 100);
                Console.WriteLine("How much do you want to bet?");
                do
                {
                    var parseSuccess = Int32.TryParse(Console.ReadLine(), out newBid);
                    if (newBid > money)
                    {
                        Console.WriteLine("You lack funds to bid so high!");
                    }
                    else if (newBid < lowerBound)
                    {
                        Console.WriteLine($"You have to bid at least ${lowerBound}.");
                    }
                    else if (newBid % 10 != 0)
                    {
                        Console.WriteLine("The lowest denomination is $10.");
                    }
                    if (!parseSuccess || newBid > money || newBid < lowerBound || newBid % 10 != 0)
                    {
                        Console.ReadKey(true);
                        ConsoleEditor.ClearLastLines(2);
                    }
                } while (newBid > money || newBid < lowerBound || newBid % 10 != 0);
                ConsoleEditor.ClearLastLines(2);
            }

            // Non-user player takes turn.
            else
            {
                double playerRankCoefficient    = ((double)rank.First().Key + 1) / 20.0;
                double highCardValueCoefficient = ((double)hand.Last().Value + 1) / 100.0;

                newBid = Math.Min(currentBid + 300, (int)Math.Ceiling(currentBid *
                                                                      (1 + playerRankCoefficient + highCardValueCoefficient + (0.1 - new Random().NextDouble() * 0.2))));

                //0.15 + playerRankCoefficient + highCardValueCoefficient + (0.1 - new Random().NextDouble() * 0.2);

                // If non-user is the first bidder, take 100 as a base.
                if (currentBid == 0)
                {
                    newBid = (int)(100 *
                                   (1 + playerRankCoefficient + highCardValueCoefficient + (0.1 - new Random().NextDouble() * 0.3)));
                }

                // Trim the last digit.
                newBid -= newBid % 10;
            }

            // Overbetting protection.
            if (newBid > money + BetValue)
            {
                newBid = money + BetValue;
            }

            // How much does the player increase their bid.
            int myBidRaise = newBid - BetValue;

            // Take the chips into hand to throw them nonchalantly on the table.
            money    -= myBidRaise;
            BetValue += myBidRaise;

            Console.WriteLine($"{Name} bets ${newBid}.");
            DidRaise = true;

            // Return the difference this player made to the current bid.
            return(newBid - currentBid);
        }
Exemple #2
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;
                        }
                    }
                }
            }
        }