private void OnClickStartPlaytest(object sender, EventArgs e) { try { AgentStorageManager storageManager = new AgentStorageManager(); agent = storageManager.LoadAgentBinary(openAgentTextBox.Text); level = storageManager.LoadObject <SnakeLevel>(openLevelTextBox.Text); level.SnakeSettings.RandomNumberGenerator = new RandomNumberGenerator(); SnakePlayTestSimulator snakePlayTestSimulator = new SnakePlayTestSimulator(level); Playtest playtest = new Playtest(snakePlayTestSimulator, (TestType)playtestTypesList.SelectedIndex); playtestResults = playtest.RunPlaytest(agent, Convert.ToInt32(numberOfSimulations.Value)); failedSimulationsAbsolute.Text = $"Number of failed tests: {playtestResults.NumberOfFailedTests} of {playtestResults.TestResults.Count}"; failedSimulationsPercent.Text = $"Percentage tests failed: {playtestResults.FailedPercentage}%"; resultsChart.Series[0].Points.Clear(); resultsChart.Series[1].Points.Clear(); resultsChart.Series[0].Points.AddXY("Failed", playtestResults.FailedPercentage); resultsChart.Series[1].Points.AddXY("Passed", 100 - playtestResults.FailedPercentage); resultsLayout.Show(); } catch (Exception exception) { MessageBox.Show($"Playtest failed! Error: {exception.Message}"); } }
/// <summary> /// Initializes a new instance of the class <see cref="Playtest"/> /// based on the specified simulator and test type. /// </summary> /// <param name="playTestSimulator"></param> /// <param name="testType"></param> public Playtest(SnakePlayTestSimulator playTestSimulator, TestType testType) { this.playTestSimulator = playTestSimulator; this.testType = testType; }