private void UpdateRunnerProfits() { var totalIfLose = Runners.Sum(r => r.Value.IfLose); foreach (var(_, runner) in Runners) { runner.Profit = Math.Round( runner.IfWin + totalIfLose - runner.IfLose, 2); } }
/// <summary> /// Calculating winner according this algorythm /// https://en.wikipedia.org/wiki/Alias_method and /// http://code.activestate.com/recipes/576564-walkers-alias-method-for-random-objects-with-diffe/ /// </summary> /// <returns></returns> public Runner CalculateWinner() { double sumOfAllChances = Runners.Sum(x => x.Chance(Margin)); double sumU = Math.Ceiling(sumOfAllChances); var pick = rnd.Next((int)sumU); double sum = 0; Runner res = new Runner(); foreach (var item in Runners) { sum += item.Chance(Margin); if (sum >= pick) { res = item; Runners[Runners.IndexOf(res)].winCount++; break; } } return(res); }
private void CalculateMargin() { Margin = Runners.Sum(x => x.DecimalPrice); }
/// <summary> /// Calculates the race margin for the <see cref="Runners"/>. /// </summary> private void ReCalculateRaceMargin() { _raceMargin = Math.Round(Runners.Sum(r => r.GetMargin()), 2); OnPropertyChanged(nameof(RaceMargin)); EvaluateCanRunRace(); }