Example #1
0
        /// <summary>
        /// Takes evey money pots and distribute money to the deserving players
        /// </summary>
        /// <param name="rankedPlayers">Players ranked</param>
        /// <returns>All the won pots</returns>
        public IEnumerable <WonPot> DistributeMoney(IEnumerable <EvaluatedCardHolder <PlayerCardHolder> > rankedPlayers)
        {
            IList <WonPot> pots            = new List <WonPot>();
            var            playersWithRank = rankedPlayers.ToArray();

            //Just to be sure there is no money left in play
            DepositMoneyInPlay();

            //Distribute all money pots
            while (Pots.Any())
            {
                var winners = Pots.Pop().Distribute(playersWithRank).ToArray();
                var wonPot  = new WonPot(Pots.Count, winners.Select(x => x.Value).DefaultIfEmpty(0).Sum(), winners.Where(x => x.Key != null));

                MoneyAmount -= wonPot.TotalPotAmount;

                pots.Add(wonPot);
            }

            //Create a new empty moneypot ready for the next game
            Pots.Push(new MoneyPot());

            //Return pots so they are in good order
            return(pots.OrderBy(x => x.PotId));
        }