Exemple #1
0
        private async void SimulateButton_Click(object sender, EventArgs e)
        {
            if (!running)
            {
                running = true;
            }
            else
            {
                return;
            }

            if (!Int32.TryParse(RunCount.Text, out Int32 runCount))
            {
                return;
            }

            if (_workManager == null)
            {
                _workManager = new WorkManager(SimulationParameters.Default);
            }

            List <IAiFactory> selectedAis            = _aiFactories.Where(t => AiList.SelectedItems.ContainsKey(t.Name)).ToList();
            ILevelGenerator   selectedLevelGenerator = _levelGenerators[LevelGeneratorName.Text];

            var progress = new Progress <Int32>(UpdateProgress);

            _completedCount = 0;
            _stopwatch.Reset();
            UpdateStatus();

            Timer.Start();
            _stopwatch.Start();
            (var results, var worstSim, var worstAi) = await _workManager.Simulate(selectedAis, selectedLevelGenerator, runCount, progress);

            _stopwatch.Stop();
            Timer.Stop();

            UpdateStatus();

            _renderSim       = worstSim;
            _renderAiFactory = worstAi;
            if (_renderSim != null && _renderSim.HasError)
            {
                MessageBox.Show("ERROR");
            }

            foreach (var aiFactory in results.Keys)
            {
                var stat = results[aiFactory];
                if (Results.Rows.Count == 0)
                {
                    DataGridViewRow row = new DataGridViewRow();
                    Results.Rows.Add(row);
                }

                (var meanMoves, var meanPower, var meanSamples, var sampleStdDev) = stat;
                Results.Rows[0].SetValues(aiFactory.Name, meanMoves.ToString("F2"), meanPower.ToString("F2"), meanSamples.ToString("F2"), sampleStdDev.ToString("F2"));
            }
            running = false;
        }
Exemple #2
0
        private async void SimulateButton_Click(object sender, EventArgs e)
        {
            if (!running)
            {
                running = true;
            }
            else
            {
                return;
            }

            if (!Int32.TryParse(RunCount.Text, out Int32 runCount))
            {
                return;
            }

            WorkManager manager = new WorkManager();

            List <IAiFactory> selectedAis = aiFactories.Where(t => AiList.SelectedItems.ContainsKey(t.Name)).ToList();

            TimeUsed.Text = "Working...";
            var stopwatch = Stopwatch.StartNew();

            (var results, var worstSim, var worstAi) = await manager.Simulate(selectedAis, runCount);

            stopwatch.Stop();
            TimeUsed.Text = stopwatch.Elapsed.TotalSeconds.ToString();

            _renderSim       = worstSim;
            _renderAiFactory = worstAi;
            if (_renderSim != null && _renderSim.HasError)
            {
                MessageBox.Show("ERROR");
            }

            foreach (var aiFactory in results.Keys)
            {
                var stat = results[aiFactory];
                if (Results.Rows.Count == 0)
                {
                    DataGridViewRow row = new DataGridViewRow();
                    Results.Rows.Add(row);
                }

                (var meanMoves, var meanPower, var meanSamples, var sampleStdDev) = stat;
                Results.Rows[0].SetValues(aiFactory.Name, meanMoves.ToString("F2"), meanPower.ToString("F2"), meanSamples.ToString("F2"), sampleStdDev.ToString("F2"));
            }
            running = false;
        }