Пример #1
0
        internal async Task <(Dictionary <IAiFactory, (Double meanMoves, Double meanPower, Double meanSamples, Double sampleStdDev)> aggregates, CompletedSimulation worstSim, IAiFactory worstAi)> Simulate(IList <IAiFactory> aiFactories, ILevelGenerator levelGenerator, Int32 runCount, IProgress <Int32> progress)
        {
            var   aggregates             = new Dictionary <IAiFactory, (Double meanMoves, Double meanPower, Double meanSamples, Double sampleStdDev)>();
            Int32 initialLevelSeed       = NextLevelSeed;
            CompletedSimulation worstSim = null;
            IAiFactory          worstAi  = null;

            foreach (var aiFactory in aiFactories)
            {
                var simulator = new Simulator(Parameters, levelGenerator, aiFactory, initialLevelSeed);

                using Completer completer = Completer.Create(Path.Combine(OutputDirectory, $"RoverSim-{aiFactory.Name}.csv"), progress);

                await simulator.SimulateAsync(runCount, completer.Consume);

                NextLevelSeed = simulator.NextLevelSeed;

                aggregates[aiFactory] = completer.GetAggregates();
                worstSim = Completer.ChooseWorst(worstSim, completer.WorstSim);
                if (worstSim == completer.WorstSim)
                {
                    worstAi = aiFactory;
                }
            }

            return(aggregates, worstSim, worstAi);
        }
Пример #2
0
        internal async Task <(Dictionary <IAiFactory, (Double meanMoves, Double meanPower, Double meanSamples, Double sampleStdDev)> aggregates, CompletedSimulation worstSim, IAiFactory worstAi)> Simulate(IList <IAiFactory> aiFactories, Int32 runCount)
        {
            var aggregates = new Dictionary <IAiFactory, (Double meanMoves, Double meanPower, Double meanSamples, Double sampleStdDev)>();
            CompletedSimulation worstSim = null;
            IAiFactory          worstAi  = null;
            Int32 levelSeed = Rando.Next(Int32.MinValue, Int32.MaxValue);

            foreach (var aiFactory in aiFactories)
            {
                var levelRand             = new Random(levelSeed);
                var levelGeneratorFactory = new OpenCheckingGeneratorFactory(new DefaultLevelGeneratorFactory(), 6);
                var roverFactory          = new DefaultRoverFactory();
                var simulator             = new Simulator(levelGeneratorFactory, roverFactory, aiFactory);

                using (Completer completer = Completer.Create(Path.Combine(OutputDirectory, $"RoverSim-{aiFactory.Name}.csv")))
                {
                    await simulator.SimulateAsync(runCount, completer.Consume);

                    aggregates[aiFactory] = completer.GetAggregates();
                    worstSim = Completer.ChooseWorst(worstSim, completer.WorstSim);
                    if (worstSim == completer.WorstSim)
                    {
                        worstAi = aiFactory;
                    }
                }
            }

            return(aggregates, worstSim, worstAi);
        }