コード例 #1
0
        /// <summary>
        /// Runs the simulation with the given configuration.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        /// <exception cref="AggregateException">One or more exceptions occurred during the running of the simulation.</exception>
        private static SimulationResult RunSimulation(Configuration configuration)
        {
            var results = new List <SimulationResult>();
            var runner  = new SimulationRunner(configuration.Parallelism);

            foreach (var availablePlayerType in configuration.AvailablePlayers)
            {
                var players = new List <AvailablePlayer> {
                    availablePlayerType
                };
                for (var i = 1; i < 5; i++)
                {
                    players.Add(availablePlayerType);
                    try
                    {
                        var result = runner.Run(players, configuration.Runs);
                        results.Add(result);
                        //Console.WriteLine($"{availablePlayerType}, {i} players: avg: {result.AverageNumberOfCardsLeft.ToString("N1", NumberFormatInfo.InvariantInfo)} (super: {result.PercentageExcellentResult.ToString("N0", NumberFormatInfo.InvariantInfo)}, perfect: {result.PercentagePerfectResult.ToString("N0", NumberFormatInfo.InvariantInfo)}, min: {result.MinNumberOfCardsLeft} - max: {result.MaxNumberOfCardsLeft})");
                    }
                    catch (OperationCanceledException)
                    {
                        Console.WriteLine("Run was cancelled!");
                    }
                }
            }

            return(new SimulationResult((int)results.Average(x => x.MinNumberOfCardsLeft),
                                        (int)results.Average(x => x.MaxNumberOfCardsLeft),
                                        results.Average(x => x.AverageNumberOfCardsLeft),
                                        results.Average(x => x.PercentageExcellentResult),
                                        results.Average(x => x.PercentagePerfectResult)));
        }
コード例 #2
0
        /// <summary>
        /// Runs the simulation with the given configuration.
        /// </summary>
        /// <param name="configuration">The configuration.</param>
        /// <exception cref="AggregateException">One or more exceptions occurred during the running of the simulation.</exception>
        private static void RunSimulation(Configuration configuration)
        {
            Console.WriteLine();
            Console.WriteLine("Running the simulation...");
            Console.WriteLine();
            var runner = new SimulationRunner(configuration.Parallelism);

            foreach (var availablePlayerType in configuration.AvailablePlayers)
            {
                var players = new List <AvailablePlayer>();
                for (var i = 1; i < 6; i++)
                {
                    players.Add(availablePlayerType);
                    try
                    {
                        var result = runner.Run(players, configuration.Runs);
                        Console.WriteLine($"{availablePlayerType}, {i} players: avg: {result.AverageNumberOfCardsLeft.ToString("N1", NumberFormatInfo.InvariantInfo)} (super: {result.PercentageExcellentResult.ToString("P0", NumberFormatInfo.InvariantInfo)}, perfect: {result.PercentagePerfectResult.ToString("P0", NumberFormatInfo.InvariantInfo)}, min: {result.MinNumberOfCardsLeft} - max: {result.MaxNumberOfCardsLeft})");
                    }
                    catch (OperationCanceledException)
                    {
                        Console.WriteLine("Run was cancelled!");
                    }
                }
            }
        }