Пример #1
0
        /// <summary>
        /// Updates the balance of all players in light of their bets and the dealer's
        /// hand.
        /// </summary>
        /// <param name="dealerPlayer">Player object representing the dealer.</param>
        public void CalculateBalance(BlackjackPlayer dealerPlayer)
        {
            for (int playerIndex = 0; playerIndex < players.Count; playerIndex++)
            {
                BlackjackPlayer player = (BlackjackPlayer)players[playerIndex];

                // Calculate first factor, which represents the amount of the first
                // hand bet which returns to the player
                float factor = CalculateFactorForHand(dealerPlayer, player,
                                                      HandTypes.First);


                if (player.IsSplit)
                {
                    // Calculate the return factor for the second hand
                    float factor2 = CalculateFactorForHand(dealerPlayer, player,
                                                           HandTypes.Second);
                    // Calculate the initial bet performed by the player
                    float initialBet =
                        player.BetAmount /
                        ((player.Double ? 2f : 1f) + (player.SecondDouble ? 2f : 1f));

                    float bet1 = initialBet * (player.Double ? 2f : 1f);
                    float bet2 = initialBet * (player.SecondDouble ? 2f : 1f);

                    // Update the balance in light of the bets and results
                    player.Balance += bet1 * factor + bet2 * factor2;

                    if (player.IsInsurance && dealerPlayer.BlackJack)
                    {
                        player.Balance += initialBet;
                    }
                }
                else
                {
                    if (player.IsInsurance && dealerPlayer.BlackJack)
                    {
                        player.Balance += player.BetAmount;
                    }

                    // Update the balance in light of the bets and results
                    player.Balance += player.BetAmount * factor;
                }

                player.ClearBet();
            }
        }