Exemple #1
0
        private bool PlayGame(IList <Day22Player> players, out Day22Player gameWinner)
        {
            while (players.Count(x => x.Cards.Count > 0) > 1)
            {
                IDictionary <Day22Player, Day22Card> cardPlayers = new Dictionary <Day22Player, Day22Card>();
                foreach (var player in players)
                {
                    var currentCard = player.Cards.Dequeue();

                    cardPlayers.Add(player, currentCard);
                }

                var highestPlayerCard = cardPlayers.OrderByDescending(x => x.Value.Value).FirstOrDefault();

                foreach (var card in cardPlayers.Values.OrderByDescending(x => x.Value))
                {
                    highestPlayerCard.Key.Cards.Enqueue(card);
                }
            }

            gameWinner = players.OrderByDescending(x => x.Cards.Count).FirstOrDefault();
            return(true);
        }
Exemple #2
0
 private static int CalculateScore(Day22Player winner)
 {
     return(winner.Cards.Reverse().Select((item, index) => (index + 1) * item.Value).Sum());
 }