2021-06-16 09:34:46 +08:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
|
|
|
|
using System;
|
2021-06-13 21:18:35 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using osu.Game.Rulesets.Difficulty.Skills;
|
|
|
|
|
using osu.Game.Rulesets.Mods;
|
|
|
|
|
using System.Linq;
|
2021-06-17 01:54:22 +08:00
|
|
|
|
using osu.Framework.Utils;
|
2021-06-13 21:18:35 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Osu.Difficulty.Skills
|
|
|
|
|
{
|
2021-08-17 21:39:18 +08:00
|
|
|
|
public abstract class OsuStrainSkill : StrainSkill
|
2021-06-13 21:18:35 +08:00
|
|
|
|
{
|
2021-06-18 03:41:06 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The number of sections with the highest strains, which the peak strain reductions will apply to.
|
|
|
|
|
/// This is done in order to decrease their impact on the overall difficulty of the map for this skill.
|
|
|
|
|
/// </summary>
|
2021-06-15 01:22:35 +08:00
|
|
|
|
protected virtual int ReducedSectionCount => 10;
|
2021-06-18 03:41:06 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The baseline multiplier applied to the section with the biggest strain.
|
|
|
|
|
/// </summary>
|
2021-06-16 21:13:46 +08:00
|
|
|
|
protected virtual double ReducedStrainBaseline => 0.75;
|
2021-06-18 03:41:06 +08:00
|
|
|
|
|
2024-05-24 02:08:32 +08:00
|
|
|
|
protected List<double> ObjectStrains = new List<double>();
|
|
|
|
|
protected double Difficulty;
|
2022-02-14 09:53:03 +08:00
|
|
|
|
|
2021-08-17 06:46:56 +08:00
|
|
|
|
protected OsuStrainSkill(Mod[] mods)
|
2021-06-16 09:34:46 +08:00
|
|
|
|
: base(mods)
|
2021-06-13 21:18:35 +08:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-16 09:34:46 +08:00
|
|
|
|
public override double DifficultyValue()
|
2021-06-13 21:18:35 +08:00
|
|
|
|
{
|
2024-05-24 02:08:32 +08:00
|
|
|
|
Difficulty = 0;
|
2021-06-13 21:18:35 +08:00
|
|
|
|
double weight = 1;
|
|
|
|
|
|
2022-05-03 15:06:20 +08:00
|
|
|
|
// Sections with 0 strain are excluded to avoid worst-case time complexity of the following sort (e.g. /b/2351871).
|
|
|
|
|
// These sections will not contribute to the difficulty.
|
|
|
|
|
var peaks = GetCurrentStrainPeaks().Where(p => p > 0);
|
|
|
|
|
|
2024-02-09 01:01:00 +08:00
|
|
|
|
List<double> strains = peaks.OrderDescending().ToList();
|
2021-06-13 21:18:35 +08:00
|
|
|
|
|
2021-06-16 09:34:46 +08:00
|
|
|
|
// We are reducing the highest strains first to account for extreme difficulty spikes
|
2021-06-17 01:55:19 +08:00
|
|
|
|
for (int i = 0; i < Math.Min(strains.Count, ReducedSectionCount); i++)
|
2021-06-13 21:18:35 +08:00
|
|
|
|
{
|
2021-06-18 03:41:06 +08:00
|
|
|
|
double scale = Math.Log10(Interpolation.Lerp(1, 10, Math.Clamp((float)i / ReducedSectionCount, 0, 1)));
|
|
|
|
|
strains[i] *= Interpolation.Lerp(ReducedStrainBaseline, 1.0, scale);
|
2021-06-13 21:18:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Difficulty is the weighted sum of the highest strains from every section.
|
|
|
|
|
// We're sorting from highest to lowest strain.
|
2024-02-09 01:01:00 +08:00
|
|
|
|
foreach (double strain in strains.OrderDescending())
|
2021-06-13 21:18:35 +08:00
|
|
|
|
{
|
2024-05-24 02:08:32 +08:00
|
|
|
|
Difficulty += strain * weight;
|
2021-06-13 21:18:35 +08:00
|
|
|
|
weight *= DecayWeight;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-03 23:37:20 +08:00
|
|
|
|
return Difficulty;
|
2021-06-13 21:18:35 +08:00
|
|
|
|
}
|
2021-12-27 07:51:49 +08:00
|
|
|
|
|
2021-12-30 07:49:07 +08:00
|
|
|
|
/// <summary>
|
2022-01-05 01:33:23 +08:00
|
|
|
|
/// Returns the number of strains weighted against the top strain.
|
2022-01-04 06:22:32 +08:00
|
|
|
|
/// The result is scaled by clock rate as it affects the total number of strains.
|
2021-12-30 07:49:07 +08:00
|
|
|
|
/// </summary>
|
2022-02-19 23:33:28 +08:00
|
|
|
|
public double CountDifficultStrains()
|
2021-12-27 07:51:49 +08:00
|
|
|
|
{
|
2024-05-26 21:21:47 +08:00
|
|
|
|
if (Difficulty == 0)
|
2024-05-26 18:24:06 +08:00
|
|
|
|
return 0.0;
|
|
|
|
|
|
2024-05-24 02:08:32 +08:00
|
|
|
|
double consistentTopStrain = Difficulty / 10; // What would the top strain be if all strain values were identical
|
2024-04-12 22:43:33 +08:00
|
|
|
|
// Use a weighted sum of all strains. Constants are arbitrary and give nice values
|
2024-05-24 02:08:32 +08:00
|
|
|
|
return ObjectStrains.Sum(s => 1.1 / (1 + Math.Exp(-10 * (s / consistentTopStrain - 0.88))));
|
2021-12-27 07:51:49 +08:00
|
|
|
|
}
|
2024-08-05 21:08:30 +08:00
|
|
|
|
|
|
|
|
|
public static double DifficultyToPerformance(double difficulty) => Math.Pow(5.0 * Math.Max(1.0, difficulty / 0.0675) - 4.0, 3.0) / 100000.0;
|
2021-06-13 21:18:35 +08:00
|
|
|
|
}
|
2024-05-24 02:08:32 +08:00
|
|
|
|
}
|