예제 #1
0
        public void Part2()
        {
            int[] rollOutcomes = new int[] { 0, 0, 0, 1, 3, 6, 7, 6, 3, 1 };

            long p1Wins = 0;
            long p2Wins = 0;

            Queue <DiceGame> inProgressGames = new Queue <DiceGame>()
            {
            };

            inProgressGames.Enqueue(ReadGameFromFile());

            while (inProgressGames.Count > 0)
            {
                DiceGame previousRound = inProgressGames.Dequeue();

                for (int p1Roll = 3; p1Roll < 10; p1Roll++)
                {
                    DiceGame p1Round = previousRound.Player1Rolls(p1Roll, rollOutcomes[p1Roll]);

                    if (p1Round.IsComplete(21))
                    {
                        p1Wins += p1Round.Combos;
                        continue;
                    }

                    for (int p2Roll = 3; p2Roll < 10; p2Roll++)
                    {
                        DiceGame p2Round = p1Round.Player2Rolls(p2Roll, rollOutcomes[p2Roll]);

                        if (p2Round.IsComplete(21))
                        {
                            p2Wins += p2Round.Combos;
                            continue;
                        }

                        inProgressGames.Enqueue(p2Round);
                    }
                }
            }
            long result = Math.Max(p1Wins, p2Wins);

            Assert.Equal(48868319769358, result);
        }