Example #1
0
        private double CalculateDifficulty(int nobjects)
        {
            double actualStrainStep = c_strainStep * ModsUtils.GetTimeRate(_mods);

            List <double> highestStrains  = new List <double>();
            double        intervalEndTime = actualStrainStep;
            double        maximumStrain   = 0;

            ManiaBeatmapObject prev = null;

            for (int i = 0; i < nobjects; i++)
            {
                ManiaBeatmapObject note = Beatmap.Objects[i] as ManiaBeatmapObject;

                Debug.Assert(note != null, nameof(note) + " != null");
                while (note.StartTime > intervalEndTime)
                {
                    highestStrains.Add(maximumStrain);

                    if (prev == null)
                    {
                        maximumStrain = 0;
                    }
                    else
                    {
                        double individualDecay = Math.Pow(ManiaBeatmapObject.INDIVIDUAL_DECAY_BASE, (intervalEndTime - prev.StartTime) / 1000.0);
                        double overallDecay    = Math.Pow(ManiaBeatmapObject.OVERALL_DECAY_BASE, (intervalEndTime - prev.StartTime) / 1000.0);
                        maximumStrain = prev.IndividualStrain * individualDecay + prev.OverallStrain * overallDecay;
                    }

                    intervalEndTime += actualStrainStep;
                }

                double strain = note.IndividualStrain + note.OverallStrain;
                if (strain > maximumStrain)
                {
                    maximumStrain = strain;
                }

                prev = note;
            }

            double diff   = 0;
            double weigth = 1;

            highestStrains.Sort((a, b) => b.CompareTo(a));

            foreach (var strain in highestStrains)
            {
                diff   += strain * weigth;
                weigth *= c_decayWeight;
            }

            return(diff);
        }
        private double CalculateDifficulty(int nobjects)
        {
            double actual_strain_step = STRAIN_STEP * m_mods.TimeRate;

            List <double> highest_strains   = new List <double>();
            double        interval_end_time = actual_strain_step;
            double        maximum_strain    = 0;

            ManiaBeatmapObject prev = null;

            for (int i = 0; i < nobjects; i++)
            {
                ManiaBeatmapObject note = Beatmap.Objects[i] as ManiaBeatmapObject;

                while (note.StartTime > interval_end_time)
                {
                    highest_strains.Add(maximum_strain);

                    if (prev == null)
                    {
                        maximum_strain = 0;
                    }
                    else
                    {
                        double individual_decay = Math.Pow(ManiaBeatmapObject.INDIVIDUAL_DECAY_BASE, (interval_end_time - prev.StartTime) / 1000.0);
                        double overall_decay    = Math.Pow(ManiaBeatmapObject.OVERALL_DECAY_BASE, (interval_end_time - prev.StartTime) / 1000.0);
                        maximum_strain = prev.IndividualStrain * individual_decay + prev.OverallStrain * overall_decay;
                    }

                    interval_end_time += actual_strain_step;
                }

                double strain = note.IndividualStrain + note.OverallStrain;
                if (strain > maximum_strain)
                {
                    maximum_strain = strain;
                }

                prev = note;
            }

            double diff   = 0;
            double weigth = 1;

            highest_strains.Sort((a, b) => b.CompareTo(a));

            foreach (var strain in highest_strains)
            {
                diff   += strain * weigth;
                weigth *= DECAY_WEIGHT;
            }

            return(diff);
        }