1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 10:33:30 +08:00

Implement stateless colour evaluator and required encoding changes

This commit is contained in:
vun 2022-07-21 19:15:22 +08:00
parent 7917a60e3c
commit e4086b058b
7 changed files with 99 additions and 64 deletions

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using osu.Game.Rulesets.Difficulty.Preprocessing;
using osu.Game.Rulesets.Taiko.Difficulty.Preprocessing;
using osu.Game.Rulesets.Taiko.Difficulty.Preprocessing.Colour;
using osu.Game.Rulesets.Taiko.Difficulty.Preprocessing.Colour.Data;
@ -18,19 +19,26 @@ namespace osu.Game.Rulesets.Taiko.Difficulty.Evaluators
/// <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)
private static double sigmoid(double val, double center, double width, double middle, double height)
{
double sigmoid = Math.Tanh(Math.E * -(val - center) / width);
return sigmoid * (height / 2) + middle;
}
/// <summary>
/// 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>
/// Evaluate the difficulty of the first note of a <see cref="MonoEncoding"/>.
/// </summary>
public static double EvaluateDifficultyOf(int i)
public static double EvaluateDifficultyOf(MonoEncoding encoding)
{
return Sigmoid(i, 2, 2, 0.5, 1);
return sigmoid(encoding.Index, 2, 2, 0.5, 1) * EvaluateDifficultyOf(encoding.Parent!) * 0.5;
}
/// <summary>
/// Evaluate the difficulty of the first note of a <see cref="ColourEncoding"/>.
/// </summary>
public static double EvaluateDifficultyOf(ColourEncoding encoding)
{
return sigmoid(encoding.Index, 2, 2, 0.5, 1) * EvaluateDifficultyOf(encoding.Parent!);
}
/// <summary>
@ -38,31 +46,22 @@ namespace osu.Game.Rulesets.Taiko.Difficulty.Evaluators
/// </summary>
public static double EvaluateDifficultyOf(CoupledColourEncoding encoding)
{
return 1 - Sigmoid(encoding.RepetitionInterval, 2, 2, 0.5, 1);
return 2 * (1 - sigmoid(encoding.RepetitionInterval, 2, 2, 0.5, 1));
}
/// <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)
public static double EvaluateDifficultyOf(DifficultyHitObject hitObject)
{
double coupledEncodingDifficulty = 2 * EvaluateDifficultyOf(encoding);
encoding.Payload[0].Payload[0].EncodedData[0].Colour!.EvaluatedDifficulty += coupledEncodingDifficulty;
TaikoDifficultyHitObjectColour colour = ((TaikoDifficultyHitObject)hitObject).Colour;
double difficulty = 0.0d;
for (int i = 0; i < encoding.Payload.Count; i++)
{
ColourEncoding colourEncoding = encoding.Payload[i];
double colourEncodingDifficulty = EvaluateDifficultyOf(i) * coupledEncodingDifficulty;
colourEncoding.Payload[0].EncodedData[0].Colour!.EvaluatedDifficulty += colourEncodingDifficulty;
if (colour.MonoEncoding != null) // Difficulty for MonoEncoding
difficulty += EvaluateDifficultyOf(colour.MonoEncoding);
if (colour.ColourEncoding != null) // Difficulty for ColourEncoding
difficulty += EvaluateDifficultyOf(colour.ColourEncoding);
if (colour.CoupledColourEncoding != null) // Difficulty for CoupledColourEncoding
difficulty += EvaluateDifficultyOf(colour.CoupledColourEncoding);
for (int j = 0; j < colourEncoding.Payload.Count; j++)
{
MonoEncoding monoEncoding = colourEncoding.Payload[j];
monoEncoding.EncodedData[0].Colour!.EvaluatedDifficulty += EvaluateDifficultyOf(j) * colourEncodingDifficulty * 0.5;
}
}
return difficulty;
}
}
}

View File

@ -17,6 +17,13 @@ namespace osu.Game.Rulesets.Taiko.Difficulty.Preprocessing.Colour.Data
/// </summary>
public List<MonoEncoding> Payload { get; private set; } = new List<MonoEncoding>();
public CoupledColourEncoding? Parent;
/// <summary>
/// Index of this encoding within it's parent encoding
/// </summary>
public int Index;
/// <summary>
/// Determine if this <see cref="ColourEncoding"/> is a repetition of another <see cref="ColourEncoding"/>. This
/// is a strict comparison and is true if and only if the colour sequence is exactly the same.

View File

@ -19,6 +19,13 @@ namespace osu.Game.Rulesets.Taiko.Difficulty.Preprocessing.Colour.Data
/// </summary>
public List<TaikoDifficultyHitObject> EncodedData { get; private set; } = new List<TaikoDifficultyHitObject>();
public ColourEncoding? Parent;
/// <summary>
/// Index of this encoding within it's parent encoding
/// </summary>
public int Index;
public int RunLength => EncodedData.Count;
}
}

View File

@ -3,7 +3,6 @@
using System.Collections.Generic;
using osu.Game.Rulesets.Difficulty.Preprocessing;
using osu.Game.Rulesets.Taiko.Difficulty.Evaluators;
using osu.Game.Rulesets.Taiko.Difficulty.Preprocessing.Colour.Data;
using osu.Game.Rulesets.Taiko.Objects;
@ -25,22 +24,36 @@ namespace osu.Game.Rulesets.Taiko.Difficulty.Preprocessing.Colour
List<TaikoDifficultyHitObjectColour> colours = new List<TaikoDifficultyHitObjectColour>();
List<CoupledColourEncoding> encodings = Encode(hitObjects);
// Assign colour to objects
// Assign indexing and encoding data to all relevant objects. Only the first note of each encoding type is
// assigned with the relevant encodings.
encodings.ForEach(coupledEncoding =>
{
coupledEncoding.Payload.ForEach(encoding =>
{
encoding.Payload.ForEach(mono =>
{
mono.EncodedData.ForEach(hitObject =>
{
hitObject.Colour = new TaikoDifficultyHitObjectColour(coupledEncoding);
});
});
});
coupledEncoding.Payload[0].Payload[0].EncodedData[0].Colour.CoupledColourEncoding = coupledEncoding;
// Pre-evaluate and assign difficulty values
ColourEvaluator.PreEvaluateDifficulties(coupledEncoding);
// TODO: Review this -
// The outermost loop is kept a ForEach loop since it doesn't need index information, and we want to
// keep i and j for ColourEncoding's and MonoEncoding's index respectively, to keep it in line with
// documentation.
// If we want uniformity for the outermost loop, it can be switched to a for loop with h or something
// else as an index
//
// While parent and index should be part of the encoding process, they are assigned here instead due to
// this being a simple one location to assign them.
for (int i = 0; i < coupledEncoding.Payload.Count; ++i)
{
ColourEncoding colourEncoding = coupledEncoding.Payload[i];
colourEncoding.Parent = coupledEncoding;
colourEncoding.Index = i;
colourEncoding.Payload[0].EncodedData[0].Colour.ColourEncoding = colourEncoding;
for (int j = 0; j < colourEncoding.Payload.Count; ++j)
{
MonoEncoding monoEncoding = colourEncoding.Payload[j];
monoEncoding.Parent = colourEncoding;
monoEncoding.Index = j;
monoEncoding.EncodedData[0].Colour.MonoEncoding = monoEncoding;
}
}
});
return colours;
@ -67,7 +80,6 @@ namespace osu.Game.Rulesets.Taiko.Difficulty.Preprocessing.Colour
previousObject == null || // First object in the list
(taikoObject.BaseObject as Hit)?.Type != (previousObject.BaseObject as Hit)?.Type
)
{
lastEncoded = new MonoEncoding();
lastEncoded.EncodedData.Add(taikoObject);
@ -111,18 +123,6 @@ namespace osu.Game.Rulesets.Taiko.Difficulty.Preprocessing.Colour
return encoded;
}
/// <summary>
/// Encodes a list of <see cref="TaikoDifficultyHitObject"/>s into a list of <see cref="CoupledColourEncoding"/>s.
/// </summary>
public static List<CoupledColourEncoding> Encode(List<DifficultyHitObject> data)
{
List<MonoEncoding> firstPass = EncodeMono(data);
List<ColourEncoding> secondPass = EncodeColour(firstPass);
List<CoupledColourEncoding> thirdPass = EncodeCoupledColour(secondPass);
return thirdPass;
}
/// <summary>
/// Encodes a list of <see cref="ColourEncoding"/>s into a list of <see cref="CoupledColourEncoding"/>s.
/// </summary>
@ -176,5 +176,17 @@ namespace osu.Game.Rulesets.Taiko.Difficulty.Preprocessing.Colour
return encoded;
}
/// <summary>
/// Encodes a list of <see cref="TaikoDifficultyHitObject"/>s into a list of <see cref="CoupledColourEncoding"/>s.
/// </summary>
public static List<CoupledColourEncoding> Encode(List<DifficultyHitObject> data)
{
List<MonoEncoding> firstPass = EncodeMono(data);
List<ColourEncoding> secondPass = EncodeColour(firstPass);
List<CoupledColourEncoding> thirdPass = EncodeCoupledColour(secondPass);
return thirdPass;
}
}
}

View File

@ -6,18 +6,26 @@ using osu.Game.Rulesets.Taiko.Difficulty.Preprocessing.Colour.Data;
namespace osu.Game.Rulesets.Taiko.Difficulty.Preprocessing.Colour
{
/// <summary>
/// Stores colour compression information for a <see cref="TaikoDifficultyHitObject"/>. This is only present for the
/// first <see cref="TaikoDifficultyHitObject"/> in a <see cref="CoupledColourEncoding"/> chunk.
/// Stores colour compression information for a <see cref="TaikoDifficultyHitObject"/>.
/// </summary>
public class TaikoDifficultyHitObjectColour
{
public CoupledColourEncoding Encoding { get; }
/// <summary>
/// <see cref="MonoEncoding"/> encoding that encodes this note, only present if this is the first note within a
/// <see cref="MonoEncoding"/>
/// </summary>
public MonoEncoding? MonoEncoding;
public double EvaluatedDifficulty = 0;
/// <summary>
/// <see cref="ColourEncoding"/> encoding that encodes this note, only present if this is the first note within
/// a <see cref="ColourEncoding"/>
/// </summary>
public ColourEncoding? ColourEncoding;
public TaikoDifficultyHitObjectColour(CoupledColourEncoding encoding)
{
Encoding = encoding;
}
/// <summary>
/// <see cref="CoupledColourEncoding"/> encoding that encodes this note, only present if this is the first note
/// within a <see cref="CoupledColourEncoding"/>
/// </summary>
public CoupledColourEncoding? CoupledColourEncoding;
}
}

View File

@ -32,7 +32,7 @@ namespace osu.Game.Rulesets.Taiko.Difficulty.Preprocessing
/// by other skills in the future.
/// This need to be writeable by TaikoDifficultyHitObjectColour so that it can assign potentially reused instances
/// </summary>
public TaikoDifficultyHitObjectColour? Colour;
public TaikoDifficultyHitObjectColour Colour;
/// <summary>
/// Creates a new difficulty hit object.
@ -53,6 +53,9 @@ namespace osu.Game.Rulesets.Taiko.Difficulty.Preprocessing
List<TaikoDifficultyHitObject> noteObjects, int index)
: base(hitObject, lastObject, clockRate, objects, index)
{
// Create the Colour object, its properties should be filled in by TaikoDifficultyPreprocessor
Colour = new TaikoDifficultyHitObjectColour();
var currentHit = hitObject as Hit;
noteDifficultyHitObjects = noteObjects;

View File

@ -6,7 +6,7 @@
using osu.Game.Rulesets.Difficulty.Preprocessing;
using osu.Game.Rulesets.Difficulty.Skills;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Taiko.Difficulty.Preprocessing;
using osu.Game.Rulesets.Taiko.Difficulty.Evaluators;
namespace osu.Game.Rulesets.Taiko.Difficulty.Skills
{
@ -29,8 +29,7 @@ namespace osu.Game.Rulesets.Taiko.Difficulty.Skills
protected override double StrainValueOf(DifficultyHitObject current)
{
double difficulty = ((TaikoDifficultyHitObject)current).Colour?.EvaluatedDifficulty ?? 0;
return difficulty;
return ColourEvaluator.EvaluateDifficultyOf(current);
}
}
}