예제 #1
0
        /// <summary>
        /// Player is checked and the current bets set to their pots.
        /// </summary>
        private void CheckPlayer(TournamentPlayer player)
        {
            if (!player.Allin)
            {
                // Calculate the player's maximum available funds.
                int playerFunds = PlayerFunds(player);

                // Set the player's bets into previous pots first before processing the current pot.
                if (pots.Count > 1)
                {
                    foreach (var pot in pots)
                    {
                        var playerPot = pot.Get(player.UserId);

                        if (playerPot != null)
                        {
                            if (playerPot.Funds < pot.Max)
                            {
                                if (playerFunds < pot.Max)
                                {
                                    // If the player cannot fully check into a previous sidepot, create a new sidepot. Player is now allin, and a part of the new sidepot.
                                    Pot.Get(player.UserId).Funds = playerFunds;
                                    NewSidePot(playerFunds, pot);
                                    player.Allin = true;
                                    Say(player.Username + " on Allin.");

                                    CheckAllins();
                                    return;
                                }
                                else
                                {
                                    // Set player's funds to the previous pot first and then recalculate their remaining funds before the next iteration.
                                    playerPot.Funds = pot.Max;
                                    playerFunds     = PlayerFunds(player);
                                }
                            }
                        }
                        else
                        {
                            // If player doesn't have a bet in the current pot, add a new playerpot and recall CheckPlayer.
                            pot.PlayerPots.Add(new PlayerPot(player.UserId, 0));
                            CheckPlayer(player);
                            return;
                        }
                    }
                }

                // Get the player's current bet, ignoring the current pot
                playerFunds = PlayerBet(player, true);

                if (player.StartingFunds < CurrentBet)
                {
                    Pot.Get(player.UserId).Funds = player.StartingFunds;
                    NewSidePot(player.StartingFunds, Pot);
                    player.Allin = true;
                    Say(player.Username + " on Allin.");
                }
                else
                {
                    if (player.StartingFunds == CurrentBet)
                    {
                        player.Allin = true;
                    }
                    Pot.Get(player.UserId).Funds = CurrentBet - playerFunds;
                    player.Checked = true;
                }
            }

            CheckAllins();
        }