Example #1
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);
        }