Beispiel #1
0
        /// <summary>
        /// Splits the pot between the winning players.
        /// </summary>
        /// <param name="players">
        /// A collection of winners, must not be null and contain at least 1 winner.
        /// </param>
        /// <remarks>
        /// The winners must all contribute evenly to the pot so they can split it.
        /// A player can't earn money from the pot when the player didn't participate in the bettings.
        /// </remarks>
        public void SplitPot(ICollection <Player> players)
        {
            // debug verifications
            Invariant.VerifyPotIsEven(this);
            Invariant.CheckPlayerSplit(this, players);

            // calculate the win amount per player
            int winAmount = Money / players.Count;

            foreach (Player player in players)
            {
                if (participatingPlayers.Contains(player)) // assure the player has participated in the bet
                {
                    player.Money += winAmount;
                }
                else
                {
                    throw new InvalidOperationException("pot can be splitted only between participating players");
                }
            }
            // if any remaineder exists, add it to the first player
            int remainder = Money % players.Count;

            players.First().Money += remainder;
            // Reset the pot data structures
            ResetPot();
        }