private static List <OneGameStatisticsDto> RunSimluations(GameSimluator simluator, int numberOfIterations, int numberOfProgressLogs, int maxTurns) { List <OneGameStatisticsDto> allGameStats = new List <OneGameStatisticsDto>(); int afterHowManyRunsToMakeLog = numberOfIterations / numberOfProgressLogs; DateTime simluationStartTime = DateTime.Now; Console.WriteLine($"\r\n\r\nRunning simulation with {numberOfIterations} iterations:\r\n"); for (int i = 0; i < numberOfIterations; i++) { OneGameStatisticsDto currentGameStats = simluator.Simlulate(maxTurns); allGameStats.Add(currentGameStats); bool enoughProgressMade = i % afterHowManyRunsToMakeLog == 0; if (enoughProgressMade) { int progressPercentage = 100 * i / numberOfIterations; Console.WriteLine($"Simulation progress: {progressPercentage}%"); } } DateTime simluationEndTime = DateTime.Now; TimeSpan simluationDuration = simluationEndTime - simluationStartTime; Console.WriteLine($"Simulation done. Simulation actual duration: {simluationDuration.Seconds}s\r\n"); return(allGameStats); }
public static void ExecuteStatisticalAnalysis(GameSimluator simluator, SimulationConfig simulationConfig) { List <OneGameStatisticsDto> allGameStats = RunSimluations(simluator, simulationConfig.NumberOfIterations, simulationConfig.NumberOfProgressLogs, simulationConfig.MaxTurns); //export raw results RawStatisticDataCsvExporter.ExportRawGameStatsToFile(allGameStats); //do statistical analysis GameStatisticCalculator.CalculateAndWriteStatisticConclusions(allGameStats, simulationConfig.DurationOfOneMoveInSeconds); }
static void Main(string[] args) { GameSimluator simluator = new GameSimluator(); //import board data SnakeOrLadderEntity[] gameBoard = GameBoardImporter.LoadGameBoard(IntputFileName); simluator.LoadGameBoard(gameBoard); //do a huge test SimulationConfig simulationConfig = UserInteraction.AskUserForSimulationConfig(); MonteCarloAnalysis.ExecuteStatisticalAnalysis(simluator, simulationConfig); //exeute one test live Console.WriteLine("\r\n\r\nExecuting one game with live scores:"); simluator.Simlulate(100, true); //keep program open Console.ReadLine(); }