Ejemplo n.º 1
0
        /// <summary>
        /// Sets up the empty stints for the strategy
        /// Sets option stints before prime stints by default
        /// </summary>
        /// <param name="numberOfStints">The number of stints to do in the race</param>
        /// <param name="numberOfPrimeStints">The number of stints to do on the prime tyre0</param>
        void SetupStrategyStints(int numberOfStints, int numberOfPrimeStints)
        {
            Stint tempStint;
            int   lapsThroughRace = 0;
            int   stintLength     = 0;

            //Populates option stints before prime stints
            for (int i = numberOfPrimeStints; i < numberOfStints; i++)
            {
                tempStint        = new Stint(lapsThroughRace, TyreType.Option, optionLaps);
                lapsThroughRace += optionLaps;
                listOfStints    += tempStint;
            }
            for (int i = 0; i < numberOfPrimeStints; i++)
            {
                if (i == (numberOfPrimeStints - 1))
                {
                    stintLength = t.laps - lapsThroughRace;
                }
                else
                {
                    stintLength = primeLaps;
                }
                tempStint        = new Stint(lapsThroughRace, TyreType.Prime, stintLength);
                lapsThroughRace += primeLaps;
                listOfStints    += tempStint;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Populates a stint with lap times
        /// </summary>
        /// <param name="lapsThroughRace">The race lap on which the stint will start. It is updated within the method</param>
        /// <returns>The populated stint</returns>
        Stint PopulateSingleStint(Stint stintToPopulate, ref int lapsThroughRace)
        {
            float degradation;
            float lapTime;
            float tyreDelta = 0;

            stintToPopulate.lapTimes.Clear();
            degradation = 0;

            if (stintToPopulate.tyreType == TyreType.Prime)
            {
                if (!stintToPopulate.modified)
                {
                    lapsThroughRace += primeLaps;
                }
                degradation = this.PaceParameters.PaceParameters[PaceParameterType.PrimeDegradation];
            }
            else
            {
                if (!stintToPopulate.modified)
                {
                    lapsThroughRace += optionLaps;
                }
                tyreDelta   = this.PaceParameters.PaceParameters[PaceParameterType.TyreDelta];
                degradation = this.PaceParameters.PaceParameters[PaceParameterType.OptionDegradation];
            }

            if (stintToPopulate.modified && (stintToPopulate.stintLength != 0))
            {
                lapsThroughRace += stintToPopulate.stintLength;
            }

            float fuelAddedTime;
            float fuelTimePerLap = this.PaceParameters.PaceParameters[PaceParameterType.FuelConsumption] * this.PaceParameters.PaceParameters[PaceParameterType.FuelEffect];

            int lap;

            for (lap = 0; lap < stintToPopulate.stintLength; lap++)
            {
                fuelAddedTime = (lapsInRace - stintToPopulate.startLap - lap) * (fuelTimePerLap);
                lapTime       = this.PaceParameters.PaceParameters[PaceParameterType.Pace];
                lapTime      += tyreDelta;
                lapTime      += fuelAddedTime;
                lapTime      += (lap * degradation);
                AddLapToStint(stintToPopulate, lapTime);
            }

            if (lapsThroughRace != lapsInRace)
            {
                stintToPopulate.lapTimes[lap - 1] += this.PaceParameters.PitStopLoss;
            }

            return(stintToPopulate);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Swaps two stints orders and updates the start lap accordingly
        /// </summary>
        public static void Swap(ref Stint a, ref Stint b)
        {
            Stint tempStint;
            int   stintAstartLap = a.startLap;

            tempStint = a;
            a         = b;
            b         = tempStint;

            a.startLap = stintAstartLap;
            b.startLap = stintAstartLap + a.stintLength;
        }
Ejemplo n.º 4
0
        public void SwapStints(int stintIndexA, int stintIndexB)
        {
            Stint stintA = listOfStints[stintIndexA];
            Stint stintB = listOfStints[stintIndexB];

            int lapsThroughRace = stintA.startLap;

            Stint.Swap(ref stintA, ref stintB);

            listOfStints[stintIndexA] = PopulateSingleStint(stintA, ref lapsThroughRace);
            listOfStints[stintIndexB] = PopulateSingleStint(stintB, ref lapsThroughRace);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Concatenates two stints into one longer stint, with the tyre type of the first stint
        /// </summary>
        /// <returns>The completed stint</returns>
        public static Stint Merge(Stint a, Stint b) //returns a stint of the correct length with no lap times included
        {
            Stint mergedStint = a;
            int   startLap    = a.startLap;
            int   endLap      = startLap + a.stintLength + b.stintLength;

            mergedStint.lapTimes.Clear();
            mergedStint.stintLength = endLap - startLap;

            mergedStint.modified = true;

            return(mergedStint);
        }
Ejemplo n.º 6
0
        public List <Stint> RemovePitStop(int lap)
        {
            List <Stint> newListOfStints = new List <Stint>();
            Stint        mergedStint;

            int removeStintIndex = listOfStints.FindIndex(s => s.startLap == lap);

            if (removeStintIndex >= 0)
            {
                if (removeStintIndex == 0)
                {
                    mergedStint = Stint.Merge(listOfStints[removeStintIndex], listOfStints[removeStintIndex + 1]);
                }
                else
                {
                    mergedStint = Stint.Merge(listOfStints[removeStintIndex - 1], listOfStints[removeStintIndex]);
                }

                int totalStints     = listOfStints.Count;
                int lapsThroughRace = 0;

                int stintIndex = 0;
                while (stintIndex < removeStintIndex - 1)
                {
                    newListOfStints += listOfStints[stintIndex];
                    lapsThroughRace += listOfStints[stintIndex].stintLength;
                    stintIndex++;
                }

                newListOfStints += PopulateSingleStint(mergedStint, ref lapsThroughRace);
                stintIndex      += 2;

                while (stintIndex < totalStints)
                {
                    newListOfStints += listOfStints[stintIndex];
                    lapsThroughRace += listOfStints[stintIndex].stintLength;
                    stintIndex++;
                }

                pitStops.Remove(lap);
            }
            else
            {
                newListOfStints = listOfStints;
            }

            return(newListOfStints);
        }
Ejemplo n.º 7
0
        public List <Stint> AddPitStop(int lap)
        {
            List <Stint> newListOfStints = new List <Stint>();

            int splitStintIndex = listOfStints.FindLastIndex(s => s.startLap < lap - 1);

            if (splitStintIndex >= 0)
            {
                Stint stintToSplit = listOfStints[splitStintIndex];

                int totalStints     = listOfStints.Count;
                int lapsThroughRace = 0;

                Stint[] splitStint = stintToSplit.Split(lap);

                //re-populate strategy:
                int stintIndex = 0;
                while (stintIndex < splitStintIndex)
                {
                    newListOfStints += listOfStints[stintIndex];
                    lapsThroughRace += listOfStints[stintIndex].stintLength;
                    stintIndex++;
                }

                foreach (Stint s in splitStint)
                {
                    newListOfStints += PopulateSingleStint(s, ref lapsThroughRace);
                }

                stintIndex++;

                while (stintIndex < totalStints)
                {
                    newListOfStints += listOfStints[stintIndex];
                    lapsThroughRace += listOfStints[stintIndex].stintLength;
                    stintIndex++;
                }

                pitStops.Add(lap);
            }
            else
            {
                newListOfStints = listOfStints;
            }

            return(newListOfStints);
        }
Ejemplo n.º 8
0
        //methods for adding, removing, and re-ordering stints

        /// <summary>
        /// Splits a stint at a given lap in the race
        /// </summary>
        /// <param name="splitLap">The race lap to split the stint at</param>
        /// <returns>An array of the two generated stints, each with the same tyre type</returns>
        public Stint[] Split(int splitLap)
        {
            Stint stintToSplit = this;

            Stint[] splitStints = new Stint[2];
            int     firstStintLength, secondStintLength;

            firstStintLength  = splitLap - stintToSplit.startLap;
            secondStintLength = stintToSplit.startLap + stintToSplit.stintLength - splitLap;

            splitStints[0] = new Stint(stintToSplit.startLap, stintToSplit.tyreType, firstStintLength);
            splitStints[1] = new Stint(splitLap, stintToSplit.tyreType, secondStintLength);

            splitStints[0].modified = true;
            splitStints[1].modified = true;

            return(splitStints);
        }
Ejemplo n.º 9
0
 void AddLapToStint(Stint stintToAdd, float lapTime)
 {
     stintToAdd += lapTime;
 }