2023-06-23 00:37:25 +08:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
2019-02-18 13:54:21 +08:00
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
|
|
2020-05-11 13:50:02 +08:00
|
|
|
|
using System;
|
2019-02-18 13:54:21 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
|
using osu.Game.Rulesets.Difficulty;
|
|
|
|
|
using osu.Game.Rulesets.Difficulty.Preprocessing;
|
|
|
|
|
using osu.Game.Rulesets.Difficulty.Skills;
|
|
|
|
|
using osu.Game.Rulesets.Mods;
|
2019-09-06 14:24:00 +08:00
|
|
|
|
using osu.Game.Rulesets.Scoring;
|
2019-02-18 13:54:21 +08:00
|
|
|
|
using osu.Game.Rulesets.Taiko.Difficulty.Preprocessing;
|
2022-08-15 20:38:40 +08:00
|
|
|
|
using osu.Game.Rulesets.Taiko.Difficulty.Preprocessing.Colour;
|
2019-02-18 13:54:21 +08:00
|
|
|
|
using osu.Game.Rulesets.Taiko.Difficulty.Skills;
|
|
|
|
|
using osu.Game.Rulesets.Taiko.Mods;
|
2019-09-06 14:24:00 +08:00
|
|
|
|
using osu.Game.Rulesets.Taiko.Scoring;
|
2019-02-18 13:54:21 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Taiko.Difficulty
|
|
|
|
|
{
|
|
|
|
|
public class TaikoDifficultyCalculator : DifficultyCalculator
|
|
|
|
|
{
|
2024-08-05 21:33:42 +08:00
|
|
|
|
private const double difficulty_multiplier = 0.084375;
|
|
|
|
|
private const double rhythm_skill_multiplier = 0.2 * difficulty_multiplier;
|
|
|
|
|
private const double colour_skill_multiplier = 0.375 * difficulty_multiplier;
|
|
|
|
|
private const double stamina_skill_multiplier = 0.375 * difficulty_multiplier;
|
2022-06-09 17:22:55 +08:00
|
|
|
|
|
2024-10-07 21:38:41 +08:00
|
|
|
|
public override int Version => 20241007;
|
2023-06-13 01:33:22 +08:00
|
|
|
|
|
2021-11-15 17:23:03 +08:00
|
|
|
|
public TaikoDifficultyCalculator(IRulesetInfo ruleset, IWorkingBeatmap beatmap)
|
2019-02-18 13:54:21 +08:00
|
|
|
|
: base(ruleset, beatmap)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-08 13:24:51 +08:00
|
|
|
|
protected override Skill[] CreateSkills(IBeatmap beatmap, Mod[] mods, double clockRate)
|
2020-05-11 13:50:02 +08:00
|
|
|
|
{
|
2022-06-08 13:24:51 +08:00
|
|
|
|
return new Skill[]
|
|
|
|
|
{
|
2024-06-26 02:06:42 +08:00
|
|
|
|
new Rhythm(mods),
|
|
|
|
|
new Colour(mods),
|
|
|
|
|
new Stamina(mods)
|
2022-06-08 13:24:51 +08:00
|
|
|
|
};
|
|
|
|
|
}
|
2020-05-11 13:50:02 +08:00
|
|
|
|
|
2020-08-22 23:51:35 +08:00
|
|
|
|
protected override Mod[] DifficultyAdjustmentMods => new Mod[]
|
2020-05-11 13:50:02 +08:00
|
|
|
|
{
|
2020-08-22 23:51:35 +08:00
|
|
|
|
new TaikoModDoubleTime(),
|
|
|
|
|
new TaikoModHalfTime(),
|
|
|
|
|
new TaikoModEasy(),
|
|
|
|
|
new TaikoModHardRock(),
|
|
|
|
|
};
|
2020-05-11 13:50:02 +08:00
|
|
|
|
|
2020-08-22 23:51:35 +08:00
|
|
|
|
protected override IEnumerable<DifficultyHitObject> CreateDifficultyHitObjects(IBeatmap beatmap, double clockRate)
|
2020-05-11 13:50:02 +08:00
|
|
|
|
{
|
2022-07-21 15:45:03 +08:00
|
|
|
|
List<DifficultyHitObject> difficultyHitObjects = new List<DifficultyHitObject>();
|
|
|
|
|
List<TaikoDifficultyHitObject> centreObjects = new List<TaikoDifficultyHitObject>();
|
|
|
|
|
List<TaikoDifficultyHitObject> rimObjects = new List<TaikoDifficultyHitObject>();
|
|
|
|
|
List<TaikoDifficultyHitObject> noteObjects = new List<TaikoDifficultyHitObject>();
|
|
|
|
|
|
|
|
|
|
for (int i = 2; i < beatmap.HitObjects.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
difficultyHitObjects.Add(
|
|
|
|
|
new TaikoDifficultyHitObject(
|
|
|
|
|
beatmap.HitObjects[i], beatmap.HitObjects[i - 1], beatmap.HitObjects[i - 2], clockRate, difficultyHitObjects,
|
|
|
|
|
centreObjects, rimObjects, noteObjects, difficultyHitObjects.Count)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-15 20:38:40 +08:00
|
|
|
|
TaikoColourDifficultyPreprocessor.ProcessAndAssign(difficultyHitObjects);
|
|
|
|
|
|
|
|
|
|
return difficultyHitObjects;
|
2020-05-11 13:50:02 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-19 16:45:16 +08:00
|
|
|
|
protected override DifficultyAttributes CreateDifficultyAttributes(IBeatmap beatmap, Mod[] mods, Skill[] skills, double clockRate)
|
2019-02-18 13:54:21 +08:00
|
|
|
|
{
|
2019-02-19 16:45:16 +08:00
|
|
|
|
if (beatmap.HitObjects.Count == 0)
|
2021-11-21 11:12:24 +08:00
|
|
|
|
return new TaikoDifficultyAttributes { Mods = mods };
|
2019-02-19 16:45:16 +08:00
|
|
|
|
|
2024-06-26 02:06:42 +08:00
|
|
|
|
Colour colour = (Colour)skills.First(x => x is Colour);
|
|
|
|
|
Rhythm rhythm = (Rhythm)skills.First(x => x is Rhythm);
|
|
|
|
|
Stamina stamina = (Stamina)skills.First(x => x is Stamina);
|
2020-05-22 19:50:21 +08:00
|
|
|
|
|
2024-08-05 21:33:42 +08:00
|
|
|
|
double colourRating = colour.DifficultyValue() * colour_skill_multiplier;
|
|
|
|
|
double rhythmRating = rhythm.DifficultyValue() * rhythm_skill_multiplier;
|
|
|
|
|
double staminaRating = stamina.DifficultyValue() * stamina_skill_multiplier;
|
2020-05-22 19:50:21 +08:00
|
|
|
|
|
2024-08-05 21:33:42 +08:00
|
|
|
|
double combinedRating = combinedDifficultyValue(rhythm, colour, stamina);
|
2022-07-15 20:10:20 +08:00
|
|
|
|
double starRating = rescale(combinedRating * 1.4);
|
|
|
|
|
|
2019-09-02 16:38:52 +08:00
|
|
|
|
HitWindows hitWindows = new TaikoHitWindows();
|
2021-10-02 11:34:29 +08:00
|
|
|
|
hitWindows.SetDifficulty(beatmap.Difficulty.OverallDifficulty);
|
2019-09-02 16:38:52 +08:00
|
|
|
|
|
2023-06-24 00:03:18 +08:00
|
|
|
|
TaikoDifficultyAttributes attributes = new TaikoDifficultyAttributes
|
2019-02-19 16:45:16 +08:00
|
|
|
|
{
|
2020-05-11 13:50:02 +08:00
|
|
|
|
StarRating = starRating,
|
2019-02-19 16:45:16 +08:00
|
|
|
|
Mods = mods,
|
2021-12-18 04:39:03 +08:00
|
|
|
|
StaminaDifficulty = staminaRating,
|
|
|
|
|
RhythmDifficulty = rhythmRating,
|
|
|
|
|
ColourDifficulty = colourRating,
|
2022-06-09 17:22:55 +08:00
|
|
|
|
PeakDifficulty = combinedRating,
|
2021-10-10 15:23:35 +08:00
|
|
|
|
GreatHitWindow = hitWindows.WindowFor(HitResult.Great) / clockRate,
|
2023-03-21 10:00:33 +08:00
|
|
|
|
OkHitWindow = hitWindows.WindowFor(HitResult.Ok) / clockRate,
|
2024-09-22 20:01:58 +08:00
|
|
|
|
MaxCombo = beatmap.GetMaxCombo(),
|
2019-02-19 16:45:16 +08:00
|
|
|
|
};
|
2023-06-24 00:03:18 +08:00
|
|
|
|
|
|
|
|
|
return attributes;
|
2019-02-18 13:54:21 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-08-23 01:34:16 +08:00
|
|
|
|
/// <summary>
|
2022-07-15 20:10:20 +08:00
|
|
|
|
/// Applies a final re-scaling of the star rating.
|
2020-08-23 01:34:16 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sr">The raw star rating value before re-scaling.</param>
|
|
|
|
|
private double rescale(double sr)
|
|
|
|
|
{
|
|
|
|
|
if (sr < 0) return sr;
|
|
|
|
|
|
|
|
|
|
return 10.43 * Math.Log(sr / 8 + 1);
|
|
|
|
|
}
|
2024-06-26 02:06:42 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns the combined star rating of the beatmap, calculated using peak strains from all sections of the map.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// For each section, the peak strains of all separate skills are combined into a single peak strain for the section.
|
|
|
|
|
/// The resulting partial rating of the beatmap is a weighted sum of the combined peaks (higher peaks are weighted more).
|
|
|
|
|
/// </remarks>
|
|
|
|
|
private double combinedDifficultyValue(Rhythm rhythm, Colour colour, Stamina stamina)
|
|
|
|
|
{
|
|
|
|
|
List<double> peaks = new List<double>();
|
|
|
|
|
|
|
|
|
|
var colourPeaks = colour.GetCurrentStrainPeaks().ToList();
|
|
|
|
|
var rhythmPeaks = rhythm.GetCurrentStrainPeaks().ToList();
|
|
|
|
|
var staminaPeaks = stamina.GetCurrentStrainPeaks().ToList();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < colourPeaks.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
double colourPeak = colourPeaks[i] * colour_skill_multiplier;
|
|
|
|
|
double rhythmPeak = rhythmPeaks[i] * rhythm_skill_multiplier;
|
|
|
|
|
double staminaPeak = staminaPeaks[i] * stamina_skill_multiplier;
|
|
|
|
|
|
|
|
|
|
double peak = norm(1.5, colourPeak, staminaPeak);
|
|
|
|
|
peak = norm(2, peak, rhythmPeak);
|
|
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
|
if (peak > 0)
|
|
|
|
|
peaks.Add(peak);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double difficulty = 0;
|
|
|
|
|
double weight = 1;
|
|
|
|
|
|
|
|
|
|
foreach (double strain in peaks.OrderDescending())
|
|
|
|
|
{
|
|
|
|
|
difficulty += strain * weight;
|
|
|
|
|
weight *= 0.9;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return difficulty;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns the <i>p</i>-norm of an <i>n</i>-dimensional vector.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="p">The value of <i>p</i> to calculate the norm for.</param>
|
|
|
|
|
/// <param name="values">The coefficients of the vector.</param>
|
|
|
|
|
private double norm(double p, params double[] values) => Math.Pow(values.Sum(x => Math.Pow(x, p)), 1 / p);
|
2019-02-18 13:54:21 +08:00
|
|
|
|
}
|
|
|
|
|
}
|