/// <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)); }
private void ClaimPots() { while (Pots.Any(x => x.Chips > 0)) { var currentPot = Pots.OrderByDescending(x => x.EligiblePlayers.Count()).First(x => x.Chips > 0); currentPot.EligiblePlayers.Shuffle(); var winningPlayer = currentPot.EligiblePlayers.First(); winningPlayer.Chips += currentPot.Chips; currentPot.Chips = 0; foreach (var pot in Pots.Where(x => x.Chips > 0 && x.EligiblePlayers.Contains(winningPlayer))) { winningPlayer.Chips += pot.Chips; pot.Chips = 0; } } }