1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-15 16:03:01 +08:00
osu-lazer/osu.Game.Rulesets.Osu/Difficulty/Skills/Reading.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

249 lines
8.8 KiB
C#
Raw Normal View History

2022-06-21 15:54:27 +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;
2022-06-21 15:54:27 +08:00
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Utils;
2022-06-21 15:54:27 +08:00
using osu.Game.Rulesets.Difficulty.Preprocessing;
using osu.Game.Rulesets.Difficulty.Skills;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu.Difficulty.Evaluators;
using osu.Game.Rulesets.Osu.Difficulty.Preprocessing;
2022-06-21 15:54:27 +08:00
namespace osu.Game.Rulesets.Osu.Difficulty.Skills
{
public class ReadingLowAR : GraphSkill
2022-06-21 15:54:27 +08:00
{
private readonly List<double> difficulties = new List<double>();
//private double skillMultiplier => 2.3;
private double skillMultiplier => 2;
2022-06-21 15:54:27 +08:00
public ReadingLowAR(Mod[] mods)
2022-06-21 15:54:27 +08:00
: base(mods)
{
}
public override void Process(DifficultyHitObject current)
{
double currentDifficulty = ReadingEvaluator.EvaluateDensityDifficultyOf(current) * skillMultiplier;
difficulties.Add(currentDifficulty);
if (current.Index == 0)
CurrentSectionEnd = Math.Ceiling(current.StartTime / SectionLength) * SectionLength;
while (current.StartTime > CurrentSectionEnd)
{
StrainPeaks.Add(CurrentSectionPeak);
CurrentSectionPeak = 0;
CurrentSectionEnd += SectionLength;
}
CurrentSectionPeak = Math.Max(currentDifficulty, CurrentSectionPeak);
}
2022-06-21 15:54:27 +08:00
private double reducedNoteCount => 5;
private double reducedNoteBaseline => 0.7;
2022-06-21 15:54:27 +08:00
public override double DifficultyValue()
{
double difficulty = 0;
2022-06-22 06:21:57 +08:00
// Sections with 0 difficulty 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 = difficulties.Where(p => p > 0);
2022-06-21 15:54:27 +08:00
2022-06-22 06:21:57 +08:00
List<double> values = peaks.OrderByDescending(d => d).ToList();
for (int i = 0; i < Math.Min(values.Count, reducedNoteCount); i++)
{
double scale = Math.Log10(Interpolation.Lerp(1, 10, Math.Clamp(i / reducedNoteCount, 0, 1)));
values[i] *= Interpolation.Lerp(reducedNoteBaseline, 1.0, scale);
}
values = values.OrderByDescending(d => d).ToList();
2022-06-22 06:21:57 +08:00
// Difficulty is the weighted sum of the highest strains from every section.
// We're sorting from highest to lowest strain.
for (int i = 0; i < values.Count; i++)
{
difficulty += values[i] / (i + 1);
}
2022-06-21 15:54:27 +08:00
2022-06-22 06:21:57 +08:00
return difficulty;
}
2022-06-21 15:54:27 +08:00
}
public class ReadingHighAR : GraphSkill
{
public ReadingHighAR(Mod[] mods)
: base(mods)
{
aimComponent = new HighARAimComponent(mods);
speedComponent = new HighARSpeedComponent(mods);
}
private HighARAimComponent aimComponent;
private HighARSpeedComponent speedComponent;
private readonly List<double> difficulties = new List<double>();
public override void Process(DifficultyHitObject current)
{
aimComponent.Process(current);
speedComponent.Process(current);
double power = OsuDifficultyCalculator.SumPower;
double mergedDifficulty = Math.Pow(
Math.Pow(aimComponent.CurrentSectionPeak, power) +
Math.Pow(speedComponent.CurrentSectionPeak, power), 1.0 / power);
difficulties.Add(mergedDifficulty);
if (current.Index == 0)
CurrentSectionEnd = Math.Ceiling(current.StartTime / SectionLength) * SectionLength;
while (current.StartTime > CurrentSectionEnd)
{
StrainPeaks.Add(CurrentSectionPeak);
CurrentSectionPeak = 0;
CurrentSectionEnd += SectionLength;
}
CurrentSectionPeak = Math.Max(mergedDifficulty, CurrentSectionPeak);
}
public override double DifficultyValue()
{
double power = OsuDifficultyCalculator.SumPower;
return Math.Pow(
Math.Pow(aimComponent.DifficultyValue(), power) +
Math.Pow(speedComponent.DifficultyValue(), power), 1.0 / power);
}
}
public class HighARAimComponent : OsuStrainSkill
{
public HighARAimComponent(Mod[] mods)
: base(mods)
{
}
private double currentStrain;
// private double currentRhythm;
//private double skillMultiplier => 13;
private double skillMultiplier => 14;
private double strainDecayBase => 0.15;
private double strainDecay(double ms) => Math.Pow(strainDecayBase, ms / 1000);
protected override double CalculateInitialStrain(double time, DifficultyHitObject current) => currentStrain * strainDecay(time - current.Previous(0).StartTime);
protected override double StrainValueAt(DifficultyHitObject current)
{
currentStrain *= strainDecay(current.DeltaTime);
double aimDifficulty = AimEvaluator.EvaluateDifficultyOf(current, true, ((OsuDifficultyHitObject)current).Preempt);
aimDifficulty *= ReadingEvaluator.EvaluateHighARDifficultyOf(current, true);
aimDifficulty *= skillMultiplier;
double totalStrain = currentStrain;
currentStrain += aimDifficulty;
// Warning: this line is unstable, so increasing amount of objects can decrease pp
totalStrain += aimDifficulty * (1 + ReadingEvaluator.EvaluateLowDensityBonusOf(current));
//Console.WriteLine($"{current.StartTime} - {ReadingEvaluator.EvaluateLowDensityBonusOf(current)}");
return totalStrain;
}
}
public class HighARSpeedComponent : OsuStrainSkill
{
private double skillMultiplier => 675;
private double strainDecayBase => 0.3;
private double currentStrain;
private double currentRhythm;
public HighARSpeedComponent(Mod[] mods)
: base(mods)
{
}
private double strainDecay(double ms) => Math.Pow(strainDecayBase, ms / 1000);
protected override double CalculateInitialStrain(double time, DifficultyHitObject current) => (currentStrain * currentRhythm) * strainDecay(time - current.Previous(0).StartTime);
protected override double StrainValueAt(DifficultyHitObject current)
{
OsuDifficultyHitObject currODHO = (OsuDifficultyHitObject)current;
currentStrain *= strainDecay(currODHO.StrainTime);
double speedDifficulty = SpeedEvaluator.EvaluateDifficultyOf(current) * skillMultiplier;
speedDifficulty *= ReadingEvaluator.EvaluateHighARDifficultyOf(current, false);
currentStrain += speedDifficulty;
currentRhythm = currODHO.RhythmDifficulty;
// currentRhythm *= currentRhythm; // Squaring is broken cuz rhythm is broken ((((
double totalStrain = currentStrain * currentRhythm;
return totalStrain;
}
}
public class ReadingHidden : GraphSkill
{
public ReadingHidden(Mod[] mods)
: base(mods)
{
}
private readonly List<double> difficulties = new List<double>();
private double skillMultiplier => 2.3;
public override void Process(DifficultyHitObject current)
{
double currentDifficulty = ReadingEvaluator.EvaluateHiddenDifficultyOf(current) * skillMultiplier;
difficulties.Add(currentDifficulty);
if (current.Index == 0)
CurrentSectionEnd = Math.Ceiling(current.StartTime / SectionLength) * SectionLength;
while (current.StartTime > CurrentSectionEnd)
{
StrainPeaks.Add(CurrentSectionPeak);
CurrentSectionPeak = 0;
CurrentSectionEnd += SectionLength;
}
CurrentSectionPeak = Math.Max(currentDifficulty, CurrentSectionPeak);
}
public override double DifficultyValue()
{
double difficulty = 0;
// Sections with 0 difficulty 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 = difficulties.Where(p => p > 0);
List<double> values = peaks.OrderByDescending(d => d).ToList();
// Difficulty is the weighted sum of the highest strains from every section.
// We're sorting from highest to lowest strain.
for (int i = 0; i < values.Count; i++)
{
difficulty += values[i] / (i + 1);
}
return difficulty;
}
}
2022-06-21 15:54:27 +08:00
}