public void RunMonteCarlo(int iterations) { var p1Wins = 0; _time = new TimeSpan(); for (var i = 0; i < iterations; i++) { _stopwatch.Reset(); _stopwatch.Start(); var currentState = _game.GameStates[_game.InitialStateIndex]; while (!currentState.Player1Won && !currentState.Player2Won) { var toss = _dice.Toss(); currentState = currentState.Transitions[toss]; } if (currentState.Player1Won) { p1Wins++; } _stopwatch.Stop(); _time += _stopwatch.Elapsed; } var winChance = (double)p1Wins / iterations; var time = _time.TotalMilliseconds; MyMatrixIoHandler.WriteToFileWithTimespan(IoConsts.PrefixWinChance + IoConsts.CsharpMonteCarlo, MyMatrixFormatter.GetFormattedVector(new[] { winChance }), 1, time); }
private void SolveGaussPartialPivotSparse(int testCount) { _time = new TimeSpan(); var vector = Vector; for (var i = 0; i < testCount; i++) { var matrix = new MyMatrix <double>(Matrix); vector = Vector; _stopwatch.Reset(); _stopwatch.Start(); matrix.GaussianReductionPartialPivotSparse(vector); _stopwatch.Stop(); _time += _stopwatch.Elapsed; } var time = _time.TotalMilliseconds / testCount; MyMatrixIoHandler.WriteToFileWithTimespan(IoConsts.CsharpGaussPartialPivotSparse, MyMatrixFormatter.GetFormattedVector(vector), CurrentMatrixSize, time); MyMatrixIoHandler.WriteToFileWithTimespan(IoConsts.PrefixWinChance + IoConsts.CsharpGaussPartialPivotSparse, MyMatrixFormatter.GetFormattedVector(new[] { vector[GetInitialStateIndex()] }), 1, time); }