2022-07-15 19:07:01 +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.
|
|
|
|
|
2022-06-06 12:42:49 +08:00
|
|
|
using System;
|
|
|
|
using osu.Game.Rulesets.Taiko.Difficulty.Preprocessing;
|
2022-07-05 14:41:40 +08:00
|
|
|
using osu.Game.Rulesets.Taiko.Difficulty.Preprocessing.Colour;
|
2022-07-15 19:07:01 +08:00
|
|
|
using osu.Game.Rulesets.Taiko.Difficulty.Preprocessing.Colour.Data;
|
2022-06-06 12:42:49 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Taiko.Difficulty.Evaluators
|
|
|
|
{
|
|
|
|
public class ColourEvaluator
|
|
|
|
{
|
2022-07-20 21:33:38 +08:00
|
|
|
/// <summary>
|
|
|
|
/// A sigmoid function. It gives a value between (middle - height/2) and (middle + height/2).
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="val">The input value.</param>
|
|
|
|
/// <param name="center">The center of the sigmoid, where the largest gradient occurs and value is equal to middle.</param>
|
|
|
|
/// <param name="width">The radius of the sigmoid, outside of which values are near the minimum/maximum.</param>
|
|
|
|
/// <param name="middle">The middle of the sigmoid output.</param>
|
|
|
|
/// <param name="height">The height of the sigmoid output. This will be equal to max value - min value.</param>
|
|
|
|
public static double Sigmoid(double val, double center, double width, double middle, double height)
|
2022-07-01 14:27:23 +08:00
|
|
|
{
|
2022-07-20 21:33:38 +08:00
|
|
|
double sigmoid = Math.Tanh(Math.E * -(val - center) / width);
|
|
|
|
return sigmoid * (height / 2) + middle;
|
2022-07-01 14:27:23 +08:00
|
|
|
}
|
|
|
|
|
2022-07-05 14:41:40 +08:00
|
|
|
/// <summary>
|
2022-07-21 08:52:41 +08:00
|
|
|
/// Evaluate the difficulty of the first note of a <see cref="MonoEncoding"/> or a <see cref="ColourEncoding"/>.
|
|
|
|
/// <param name="i">The index of either encoding within it's respective parent.</param>
|
2022-07-05 14:41:40 +08:00
|
|
|
/// </summary>
|
2022-07-21 08:52:41 +08:00
|
|
|
public static double EvaluateDifficultyOf(int i)
|
2022-06-06 12:42:49 +08:00
|
|
|
{
|
2022-07-20 21:33:38 +08:00
|
|
|
return Sigmoid(i, 2, 2, 0.5, 1);
|
2022-07-05 14:41:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Evaluate the difficulty of the first note of a <see cref="CoupledColourEncoding"/>.
|
|
|
|
/// </summary>
|
|
|
|
public static double EvaluateDifficultyOf(CoupledColourEncoding encoding)
|
|
|
|
{
|
2022-07-20 21:33:38 +08:00
|
|
|
return 1 - Sigmoid(encoding.RepetitionInterval, 2, 2, 0.5, 1);
|
2022-07-05 14:41:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Pre-evaluate and *assign* difficulty values of all hit objects encoded in a <see cref="CoupledColourEncoding"/>.
|
|
|
|
/// Difficulty values are assigned to <see cref="TaikoDifficultyHitObjectColour.EvaluatedDifficulty"/> of each
|
|
|
|
/// <see cref="TaikoDifficultyHitObject"/> encoded within.
|
|
|
|
/// </summary>
|
|
|
|
public static void PreEvaluateDifficulties(CoupledColourEncoding encoding)
|
|
|
|
{
|
2022-07-07 16:04:46 +08:00
|
|
|
double coupledEncodingDifficulty = 2 * EvaluateDifficultyOf(encoding);
|
2022-07-05 14:41:40 +08:00
|
|
|
encoding.Payload[0].Payload[0].EncodedData[0].Colour!.EvaluatedDifficulty += coupledEncodingDifficulty;
|
2022-07-15 19:07:01 +08:00
|
|
|
|
2022-07-05 14:41:40 +08:00
|
|
|
for (int i = 0; i < encoding.Payload.Count; i++)
|
|
|
|
{
|
|
|
|
ColourEncoding colourEncoding = encoding.Payload[i];
|
2022-07-21 08:52:41 +08:00
|
|
|
double colourEncodingDifficulty = EvaluateDifficultyOf(i) * coupledEncodingDifficulty;
|
2022-07-05 14:41:40 +08:00
|
|
|
colourEncoding.Payload[0].EncodedData[0].Colour!.EvaluatedDifficulty += colourEncodingDifficulty;
|
2022-07-15 19:07:01 +08:00
|
|
|
|
2022-07-05 14:41:40 +08:00
|
|
|
for (int j = 0; j < colourEncoding.Payload.Count; j++)
|
|
|
|
{
|
|
|
|
MonoEncoding monoEncoding = colourEncoding.Payload[j];
|
2022-07-21 08:52:41 +08:00
|
|
|
monoEncoding.EncodedData[0].Colour!.EvaluatedDifficulty += EvaluateDifficultyOf(j) * colourEncodingDifficulty * 0.5;
|
2022-07-05 14:41:40 +08:00
|
|
|
}
|
|
|
|
}
|
2022-06-06 12:42:49 +08:00
|
|
|
}
|
|
|
|
}
|
2022-06-09 17:22:55 +08:00
|
|
|
}
|