コード例 #1
0
ファイル: MarketCache.cs プロジェクト: KelvinVail/Betfair
        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);
            }
        }
コード例 #2
0
ファイル: Race.cs プロジェクト: Utilisator/HorseRace
        /// <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);
        }
コード例 #3
0
ファイル: Race.cs プロジェクト: Utilisator/HorseRace
 private void CalculateMargin()
 {
     Margin = Runners.Sum(x => x.DecimalPrice);
 }
コード例 #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();
 }