Exemplo n.º 1
0
        private void RecalculateLapTimesOfDriver(Driver driver, out RaceLap lapZero)
        {
            lapZero = null;
            var laps = Laps[driver];

            if (laps.Count == 0)
            {
                return;
            }

            laps.Sort(new Lap.ByCrossedAtTimeComparer());
            lapZero = laps[0];

            Time lastCrossedAt = laps[0].CrossedAtTime;

            for (int i = 0; i < laps.Count; i++)
            {
                laps[i].LapNumber = i;
                if (i == 0)
                {
                    continue;
                }

                Time diff = laps[i].CrossedAtTime - lastCrossedAt;
                laps[i].Time = diff;

                lastCrossedAt = laps[i].CrossedAtTime;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the specified lap by lapnumber and driver.
        /// </summary>
        /// <param name="lapNumber">The lap number.</param>
        /// <param name="driver">The driver.</param>
        /// <returns></returns>
        public RaceLap Get(int lapNumber, Driver driver)
        {
            var     l   = this[GetLapIndex(lapNumber)];
            RaceLap ret = l.FirstOrDefault(i => i.Driver == driver);

            return(ret);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Adds the lap.
        /// </summary>
        /// <param name="lapNumber">The lap number.</param>
        /// <param name="lap">The lap.</param>
        public void AddLap(int lapNumber, RaceLap lap)
        {
            while (inner.Count <= lapNumber)
            {
                inner.Add(new List <RaceLap>());
            }

            inner[GetLapIndex(lapNumber)].Add(lap);
        }
Exemplo n.º 4
0
        public int Sum(Func <RaceLap, int> selector, Func <RaceLap, RaceLap> enumerator)
        {
            int     ret     = selector(this);
            RaceLap prevLap = enumerator(this);

            if (prevLap != null)
            {
                ret += prevLap.Sum(selector, enumerator);
            }

            return(ret);
        }
        /// <summary>
        /// Adds the pit specified by enter and exit lap.
        /// </summary>
        /// <param name="firstLap">The first lap.</param>
        /// <param name="secondLap">The second lap.</param>
        public void Add(RaceLap firstLap, RaceLap secondLap)
        {
            RacePit item = new RacePit();

            item.FirstLap  = firstLap;
            item.SecondLap = secondLap;
            item.Time      = item.FirstLap.Time + item.SecondLap.Time;

            if (inner.ContainsKey(firstLap.Driver) == false)
            {
                inner.Add(firstLap.Driver, new List <RacePit>());
            }
            inner[firstLap.Driver].Add(item);
        }
Exemplo n.º 6
0
        private List <RaceLap> GetLapsByLapNumber(int lapNumber, bool searchDownForPreviousLapsForEveryDriver)
        {
            List <RaceLap> ret = new List <RaceLap>();

            ret = Laps.Get(lapNumber);

            if (searchDownForPreviousLapsForEveryDriver)
            {
                List <Driver> drivers = Laps.GetDrivers().ToList();

                foreach (var lap in ret)
                {
                    if (drivers.Contains(lap.Driver))
                    {
                        drivers.Remove(lap.Driver);
                    }
                }

                int lastDriversCount = drivers.Count;
                while (drivers.Count > 0)
                {
                    Driver driver = drivers[0];
                    for (int i = lapNumber - 1; i > 0; i--)
                    {
                        RaceLap lap = Laps.Get(i, driver);
                        if (lap != null)
                        {
                            ret.Add(lap);
                            drivers.Remove(driver);
                            break;
                        }
                    }

                    if (lastDriversCount == drivers.Count)
                    {
                        throw new Exception("Cannot get last previous lap of driver " + driver.NameSurname + ". Invalid data.");
                    }
                    else
                    {
                        lastDriversCount = drivers.Count;
                    }
                }
            }

            return(ret);
        }
Exemplo n.º 7
0
        public bool Exists(Func <RaceLap, bool> predicate, Func <RaceLap, RaceLap> enumerator)
        {
            bool ret = predicate(this);

            if (ret)
            {
                return(true);
            }

            RaceLap prevLap = enumerator(this);

            if (prevLap != null)
            {
                prevLap.Exists(predicate, enumerator);
            }

            return(false);
        }
Exemplo n.º 8
0
        public int Count(Func <RaceLap, bool> predicate, Func <RaceLap, RaceLap> enumerator)
        {
            int ret = 0;

            if (predicate(this))
            {
                ret++;
            }

            RaceLap prevLap = enumerator(this);

            if (prevLap != null)
            {
                ret += prevLap.Count(predicate, enumerator);
            }

            return(ret);
        }
Exemplo n.º 9
0
        private void BuildPositions(out RaceLap winLapOfWinner)
        {
            winLapOfWinner = null;

            Positions.ClearExceptDriverFinalStatuses();
            List <RaceLap> laps = null;

            for (int i = 1; i <= Weekend.Settings.RaceLapCount; i++)
            {
                laps = GetLapsByLapNumber(i, true);
                LinkLapsInSameLapNumber(laps);
                laps.ForEach(k => Positions.AddLap(i, k));

                if (i == Weekend.Settings.RaceLapCount)
                {
                    winLapOfWinner = laps[0] as RaceLap;
                }
            }
        }
Exemplo n.º 10
0
        private void EvaluateLaps(out RaceLap zeroLapOfPolePosition)
        {
            Minner <RaceLap> m = new Minner <RaceLap>(
                (RaceLap l) => l.CrossedAtTime
                );
            RaceLap lapZero;

            var drivers = Laps.GetDrivers();

            foreach (var driver in drivers)
            {
                RecalculateLapTimesOfDriver(driver, out lapZero);
                m.Add(lapZero as RaceLap);
                Laps.Remove(0, driver);
                RefreshLinksOfDriver(driver);
            }

            zeroLapOfPolePosition = m.MinimumItem;
        }
Exemplo n.º 11
0
        public RaceLap Min(Func <RaceLap, double> selector, Func <RaceLap, RaceLap> enumerator)
        {
            RaceLap ret = null;

            RaceLap prevLap = enumerator(this);

            if (prevLap != null)
            {
                ret = prevLap.Min(selector, enumerator);
                if (selector(this) < selector(ret))
                {
                    ret = this;
                }
            }
            else
            {
                ret = this;
            }

            return(ret);
        }
Exemplo n.º 12
0
        public void RegisterPitLaps()
        {
            this.PitLaps.Clear();

            var drivers = Laps.GetDrivers();

            foreach (var driver in drivers)
            {
                var laps = Laps[driver];
                laps.ForEach(i => i.PitState = RaceLap.ePitState.None);
                laps.Sort(new Lap.ByCrossedAtTimeComparer());

                for (int i = 1; i < laps.Count - 1; i++)
                {
                    if (laps[i].IsPitted == false)
                    {
                        continue;
                    }

                    RaceLap current = laps[i];
                    RaceLap next    = laps[i + 1];
                    this.PitLaps.Add(current, next);

                    if (current.PitState == RaceLap.ePitState.Exit)
                    {
                        current.PitState = RaceLap.ePitState.ExitAndEntry;
                    }
                    else
                    {
                        current.PitState = RaceLap.ePitState.Entry;
                    }

                    next.PitState = RaceLap.ePitState.Exit;
                }
            }
        }
Exemplo n.º 13
0
 private static IComparable _GetLapCrossedAtTime(RaceLap lap)
 {
     return(lap.CrossedAtTime);
 }