This commit is contained in:
StanR 2024-09-15 01:12:41 +05:00
parent 5e8174faa8
commit db626f168a
1 changed files with 20 additions and 20 deletions

View File

@ -3,7 +3,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using osu.Game.Rulesets.Difficulty.Preprocessing; using osu.Game.Rulesets.Difficulty.Preprocessing;
using osu.Game.Rulesets.Osu.Difficulty.Preprocessing; using osu.Game.Rulesets.Osu.Difficulty.Preprocessing;
using osu.Game.Rulesets.Osu.Objects; using osu.Game.Rulesets.Osu.Objects;
@ -12,7 +11,7 @@ namespace osu.Game.Rulesets.Osu.Difficulty.Evaluators
{ {
public static class RhythmEvaluator public static class RhythmEvaluator
{ {
private readonly struct Island : IEquatable<Island> private struct Island : IEquatable<Island>
{ {
private readonly double deltaDifferenceEpsilon; private readonly double deltaDifferenceEpsilon;
@ -21,41 +20,39 @@ public Island(double epsilon)
deltaDifferenceEpsilon = epsilon; deltaDifferenceEpsilon = epsilon;
} }
public Island(int firstDelta, double epsilon) public Island(int delta, double epsilon)
{ {
deltaDifferenceEpsilon = epsilon; deltaDifferenceEpsilon = epsilon;
AddDelta(firstDelta); Delta = Math.Max(delta, OsuDifficultyHitObject.MIN_DELTA_TIME);
} }
public List<int> Deltas { get; } = new List<int>(); public int Delta { get; private set; }
public int DeltaCount { get; private set; }
public void AddDelta(int delta) public void AddDelta(int delta)
{ {
double epsilon = deltaDifferenceEpsilon; if (Delta == default)
int existingDelta = Deltas.FirstOrDefault(x => Math.Abs(x - delta) >= epsilon); Delta = Math.Max(delta, OsuDifficultyHitObject.MIN_DELTA_TIME);
Deltas.Add(existingDelta == default ? delta : existingDelta); DeltaCount++;
} }
public double AverageDelta() => Deltas.Count > 0 ? Math.Max(Deltas.Average(), OsuDifficultyHitObject.MIN_DELTA_TIME) : 0;
public bool IsSimilarPolarity(Island other) public bool IsSimilarPolarity(Island other)
{ {
// consider islands to be of similar polarity only if they're having the same average delta (we don't want to consider 3 singletaps similar to a triple) // consider islands to be of similar polarity only if they're having the same average delta (we don't want to consider 3 singletaps similar to a triple)
return Math.Abs(AverageDelta() - other.AverageDelta()) < deltaDifferenceEpsilon && return DeltaCount % 2 == other.DeltaCount % 2 &&
Deltas.Count % 2 == other.Deltas.Count % 2; Math.Abs(Delta - other.Delta) < deltaDifferenceEpsilon;
} }
public override int GetHashCode() public override int GetHashCode()
{ {
// we need to compare all deltas and they must be in the exact same order we added them return HashCode.Combine(Delta, DeltaCount);
string joinedDeltas = string.Join(string.Empty, Deltas);
return joinedDeltas.GetHashCode();
} }
public bool Equals(Island other) public bool Equals(Island other)
{ {
return other.GetHashCode() == GetHashCode(); return Math.Abs(Delta - other.Delta) < deltaDifferenceEpsilon &&
DeltaCount == other.DeltaCount;
} }
public override bool Equals(object? obj) public override bool Equals(object? obj)
@ -113,7 +110,10 @@ public static double EvaluateDifficultyOf(DifficultyHitObject current, double cl
double prevDelta = prevObj.StrainTime; double prevDelta = prevObj.StrainTime;
double lastDelta = lastObj.StrainTime; double lastDelta = lastObj.StrainTime;
double currRatio = 1.0 + 6.0 * Math.Min(0.5, Math.Pow(Math.Sin(Math.PI / (Math.Min(prevDelta, currDelta) / Math.Max(prevDelta, currDelta))), 2)); // fancy function to calculate rhythmbonuses. // calculate how much current delta difference deserves a rhythm bonus
// this function is meant to reduce rhythm bonus for deltas that are multiples of each other (i.e 100 and 200)
double deltaDifferenceRatio = Math.Min(prevDelta, currDelta) / Math.Max(prevDelta, currDelta);
double currRatio = 1.0 + 6.0 * Math.Min(0.5, Math.Pow(Math.Sin(Math.PI / deltaDifferenceRatio), 2));
double windowPenalty = Math.Min(1, Math.Max(0, Math.Abs(prevDelta - currDelta) - deltaDifferenceEpsilon) / deltaDifferenceEpsilon); double windowPenalty = Math.Min(1, Math.Max(0, Math.Abs(prevDelta - currDelta) - deltaDifferenceEpsilon) / deltaDifferenceEpsilon);
@ -121,7 +121,7 @@ public static double EvaluateDifficultyOf(DifficultyHitObject current, double cl
if (firstDeltaSwitch) if (firstDeltaSwitch)
{ {
if (!(Math.Abs(prevDelta - currDelta) > deltaDifferenceEpsilon)) if (Math.Abs(prevDelta - currDelta) < deltaDifferenceEpsilon)
{ {
// island is still progressing // island is still progressing
island.AddDelta((int)currDelta); island.AddDelta((int)currDelta);
@ -146,7 +146,7 @@ public static double EvaluateDifficultyOf(DifficultyHitObject current, double cl
effectiveRatio *= 0.125; effectiveRatio *= 0.125;
// singletaps are easier to control // singletaps are easier to control
if (island.Deltas.Count == 1) if (island.DeltaCount == 1)
effectiveRatio *= 0.7; effectiveRatio *= 0.7;
if (!islandCounts.TryAdd(island, 1)) if (!islandCounts.TryAdd(island, 1))
@ -156,7 +156,7 @@ public static double EvaluateDifficultyOf(DifficultyHitObject current, double cl
islandCounts[island]++; islandCounts[island]++;
// repeated island (ex: triplet -> triplet) // repeated island (ex: triplet -> triplet)
double power = logistic(island.AverageDelta(), 4, 0.165, 10); double power = logistic(island.Delta, 4, 0.165, 10);
effectiveRatio *= Math.Min(3.0 / islandCounts[island], Math.Pow(1.0 / islandCounts[island], power)); effectiveRatio *= Math.Min(3.0 / islandCounts[island], Math.Pow(1.0 / islandCounts[island], power));
} }