Ejemplo n.º 1
0
        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);
            }
        }
Ejemplo n.º 2
0
        /// <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);
        }
Ejemplo n.º 3
0
 private void CalculateMargin()
 {
     Margin = Runners.Sum(x => x.DecimalPrice);
 }
Ejemplo n.º 4
0
 /// <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();
 }