예제 #1
0
 public Segment(
     string name, Time pbSplitTime = default(Time), 
     Time bestSegmentTime = default(Time), Image icon = null,
     Time splitTime = default(Time))
 {
     Comparisons = new CompositeComparisons();
     Name = name;
     PersonalBestSplitTime = pbSplitTime;
     BestSegmentTime = bestSegmentTime;
     SplitTime = splitTime;
     Icon = icon;
     SegmentHistory = new SegmentHistory();
 }
예제 #2
0
        // TODO some of the segment history is incorrect at times, most likely due to new splits being added or removed
        void CalculateOdds()
        {
            ClearOdds();

            int segmentIndex = 0;

            IRun run        = state.Run;
            int  startIndex = 0;
            int  endIndex   = run.Count;

            int previousAttempts = 0;

            Time pbDelta = Time.Zero;

            // Loop through every split
            for (int i = startIndex; i < endIndex; i++)
            {
                SegmentHistory history = state.Run[i].SegmentHistory;
                Time           pbTime  = state.Run[i].PersonalBestSplitTime;

                var attempts = history.Keys;

                // Something is wrong with the splits, due to adding new ones, etc, so just discount it.
                if (attempts.Count > run.AttemptCount || attempts.Count > previousAttempts)
                {
                    completeCurrentSplit.Add(1.0);
                    ////previousAttempts = attempts.Count + previousAttempts; // Add onto the next one as they were not used in this calculation
                }

                else
                {
                    if (i == 0)
                    {
                        // Chances of completeing current split
                        completeCurrentSplit.Add((Double)attempts.Count / run.AttemptCount);
                    }
                    else
                    {
                        // Chances of completeing current split
                        completeCurrentSplit.Add((Double)attempts.Count / previousAttempts);
                    }
                }

                int historySavedTime = 0;
                // Calculate chances of saving time on current split
                foreach (int attempt in attempts)
                {
                    Time time;
                    bool success = history.TryGetValue(attempt, out time);
                    if (success && time.RealTime != null && time.RealTime.Value <= (pbTime - pbDelta).RealTime.Value)
                    {
                        // If the previous segment saved time
                        historySavedTime++;
                    }
                }

                pbDelta += pbTime;

                if (attempts.Count > historySavedTime)
                {
                    saveTimeCurrentSplit.Add(1.0);
                    previousAttempts = attempts.Count + historySavedTime; // Add onto the next one as they were not used in this calculation
                }
                else
                {
                    // Store chances of saving time on current split
                    saveTimeCurrentSplit.Add((Double)historySavedTime / attempts.Count);
                }

                previousAttempts = attempts.Count;

                segmentIndex++;
            }

            Double previousOdds = 1;

            // Completing the run, combined probability of completing current individual splits.
            for (int i = completeCurrentSplit.Count - 1; i >= 0; i--)
            {
                completeRun.Insert(0, previousOdds * completeCurrentSplit[i]);
                previousOdds = previousOdds * completeCurrentSplit[i];
            }
        }
예제 #3
0
        public static void AddSegment(this IRun run, string name, Time pbSplitTime = default(Time), Time bestSegmentTime = default(Time), Image icon = null, Time splitTime = default(Time), SegmentHistory segmentHistory = null)
        {
            var segment = new Segment(name, pbSplitTime, bestSegmentTime, icon, splitTime);

            if (segmentHistory != null)
            {
                segment.SegmentHistory = segmentHistory;
            }
            run.Add(segment);
        }