1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-09 13:53:21 +08:00
osu-lazer/osu.Game.Rulesets.Osu/Difficulty/Evaluators/CognitionEvaluator.cs

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

243 lines
9.7 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-07-20 02:17:16 +08:00
using System.Collections.Generic;
2022-08-09 20:43:12 +08:00
using osu.Framework.Extensions.ObjectExtensions;
2022-06-21 15:54:27 +08:00
using osu.Game.Rulesets.Difficulty.Preprocessing;
using osu.Game.Rulesets.Osu.Difficulty.Preprocessing;
2022-08-11 03:04:38 +08:00
using osu.Game.Rulesets.Osu.Mods;
2022-06-21 20:15:31 +08:00
using osu.Game.Rulesets.Osu.Objects;
2022-06-21 15:54:27 +08:00
namespace osu.Game.Rulesets.Osu.Difficulty.Evaluators
{
public static class CognitionEvaluator
{
private const double cognition_window_size = 3000;
2022-08-11 02:09:42 +08:00
2022-06-21 15:54:27 +08:00
public static double EvaluateDifficultyOf(DifficultyHitObject current, bool hidden)
{
2022-08-09 20:43:12 +08:00
if (current.BaseObject is Spinner || current.Index == 0)
2022-06-21 20:15:31 +08:00
return 0;
2022-06-21 15:54:27 +08:00
var currObj = (OsuDifficultyHitObject)current;
2022-08-11 03:04:38 +08:00
var prevObj = (OsuDifficultyHitObject)current.Previous(0);
2022-06-22 06:21:57 +08:00
double currVelocity = currObj.LazyJumpDistance / currObj.StrainTime;
2022-06-21 15:54:27 +08:00
2022-08-11 03:04:38 +08:00
// Maybe I should just pass in clockrate...
var clockRateEstimate = current.BaseObject.StartTime / currObj.StartTime;
2022-08-11 02:09:42 +08:00
List<OsuDifficultyHitObject> pastVisibleObjects = retrievePastVisibleObjects(currObj);
//List<OsuDifficultyHitObject> currentVisibleObjects = retrieveCurrentVisibleObjects(currObj);
2022-06-21 15:54:27 +08:00
2022-07-20 02:17:16 +08:00
// Rather than note density being the number of on-screen objects visible at the current object,
// consider it as how many objects the current object has been visible for.
2022-08-11 02:09:42 +08:00
double noteDensityDifficulty = 1.0;
2022-06-21 15:54:27 +08:00
2022-08-11 03:04:38 +08:00
double pastObjectDifficultyInfluence = 1.0;
2022-08-11 02:09:42 +08:00
foreach (var loopObj in pastVisibleObjects)
2022-07-20 02:17:16 +08:00
{
var prevLoopObj = loopObj.Previous(0) as OsuDifficultyHitObject;
2022-08-11 02:09:42 +08:00
double loopDifficulty = currObj.OpacityAt(loopObj.BaseObject.StartTime, false);
2022-08-09 20:43:12 +08:00
2022-08-11 02:09:42 +08:00
// Small distances means objects may be cheesed, so it doesn't matter whether they are arranged confusingly.
loopDifficulty *= logistic((loopObj.MinimumJumpDistance - 90) / 15);
2022-08-09 20:43:12 +08:00
double timeBetweenCurrAndLoopObj = (currObj.BaseObject.StartTime - loopObj.BaseObject.StartTime) / clockRateEstimate;
loopDifficulty *= getTimeNerfFactor(timeBetweenCurrAndLoopObj);
2022-08-11 03:04:38 +08:00
pastObjectDifficultyInfluence += loopDifficulty;
2022-06-21 15:54:27 +08:00
}
noteDensityDifficulty = Math.Pow(3 * Math.Log(Math.Max(1, pastObjectDifficultyInfluence - 1)), 2.3);
noteDensityDifficulty *= getConstantAngleNerfFactor(currObj);
2022-10-05 08:32:05 +08:00
2022-06-22 06:21:57 +08:00
double hiddenDifficulty = 0;
2022-06-21 15:54:27 +08:00
2022-08-11 03:04:38 +08:00
if (hidden)
{
var timeSpentInvisible = getDurationSpentInvisible(currObj) / clockRateEstimate;
var isRhythmChange = (currObj.StrainTime - prevObj.StrainTime < 5);
var timeDifficultyFactor = 800 / pastObjectDifficultyInfluence;
2022-08-11 03:04:38 +08:00
hiddenDifficulty += Math.Pow(7 * timeSpentInvisible / timeDifficultyFactor, 1);
if (isRhythmChange)
hiddenDifficulty *= 1.1;
hiddenDifficulty += 2 * currVelocity;
2022-08-11 03:04:38 +08:00
}
2022-06-21 15:54:27 +08:00
double preemptDifficulty = 0.0;
2022-08-28 01:33:07 +08:00
2022-06-21 15:54:27 +08:00
if (currObj.preempt < 400)
2022-08-28 01:33:07 +08:00
{
preemptDifficulty += Math.Pow(400 - currObj.preempt, 1.5) / (10 + (currObj.StrainTime * 0.05));
2022-06-22 06:21:57 +08:00
2022-08-28 01:33:07 +08:00
// Buff spacing.
2022-10-08 03:26:56 +08:00
preemptDifficulty *= 1 + 0.6 * currVelocity;
2022-08-28 01:33:07 +08:00
// Buff rhythm.
2022-10-08 03:40:38 +08:00
preemptDifficulty *= Math.Max(1, RhythmEvaluator.EvaluateDifficultyOf(current) - 0.1);
2022-08-28 01:33:07 +08:00
// Buff small circles.
// Very arbitrary, but lets assume CS5 is when AR11 becomes more uncomfortable.
// This is likely going to need adjustments in the future as player meta develops.
preemptDifficulty *= 1 + Math.Max((30 - ((OsuHitObject)currObj.BaseObject).Radius) / 20, 0);
// Nerf repeated angles.
2022-08-28 01:33:07 +08:00
if (current.Index > 1)
{
2022-10-08 03:26:56 +08:00
preemptDifficulty *= getConstantAngleNerfFactor(currObj);
preemptDifficulty *= getConstantAngleNerfFactor(prevObj);
2022-08-28 01:33:07 +08:00
}
// Nerf constant rhythm.
preemptDifficulty *= getConstantRhythmNerfFactor(currObj);
2022-08-28 01:33:07 +08:00
}
2022-06-21 15:54:27 +08:00
double difficulty = Math.Max(preemptDifficulty, hiddenDifficulty) + noteDensityDifficulty;
2022-06-21 15:54:27 +08:00
2022-08-28 01:33:07 +08:00
// While there is slider leniency...
if (currObj.BaseObject is Slider)
difficulty *= 0.2;
2022-06-21 15:54:27 +08:00
return difficulty;
}
2022-07-20 02:17:16 +08:00
// Returns a list of objects that are visible on screen at
// the point in time at which the current object becomes visible.
2022-08-11 02:09:42 +08:00
private static List<OsuDifficultyHitObject> retrievePastVisibleObjects(OsuDifficultyHitObject current)
2022-07-20 02:17:16 +08:00
{
2022-08-11 02:09:42 +08:00
List<OsuDifficultyHitObject> objects = new List<OsuDifficultyHitObject>();
2022-07-20 02:17:16 +08:00
for (int i = 0; i < current.Index; i++)
{
2022-08-11 02:09:42 +08:00
OsuDifficultyHitObject loopObj = (OsuDifficultyHitObject)current.Previous(i);
2022-07-20 02:17:16 +08:00
2022-08-11 02:09:42 +08:00
if (loopObj.IsNull() || current.StartTime - loopObj.StartTime > cognition_window_size)
2022-07-20 02:17:16 +08:00
break;
2022-08-11 02:09:42 +08:00
objects.Add(loopObj);
2022-07-20 02:17:16 +08:00
}
return objects;
}
// Returns a list of objects that are visible on screen at
// the point in time at which the current object needs is clicked.
2022-08-11 02:09:42 +08:00
private static List<OsuDifficultyHitObject> retrieveCurrentVisibleObjects(OsuDifficultyHitObject current)
2022-07-20 02:17:16 +08:00
{
2022-08-11 02:09:42 +08:00
List<OsuDifficultyHitObject> objects = new List<OsuDifficultyHitObject>();
2022-07-20 02:17:16 +08:00
for (int i = 0; i < current.Count; i++)
{
2022-08-11 02:09:42 +08:00
OsuDifficultyHitObject loopObj = (OsuDifficultyHitObject)current.Next(i);
2022-07-20 02:17:16 +08:00
2022-08-11 02:09:42 +08:00
if (loopObj.IsNull() || (loopObj.StartTime - current.StartTime) > cognition_window_size)
2022-07-20 02:17:16 +08:00
break;
2022-08-11 02:09:42 +08:00
objects.Add(loopObj);
2022-07-20 02:17:16 +08:00
}
return objects;
}
2022-08-11 03:04:38 +08:00
private static double getDurationSpentInvisible(OsuDifficultyHitObject current)
{
var baseObject = (OsuHitObject)current.BaseObject;
double fadeOutStartTime = baseObject.StartTime - baseObject.TimePreempt + baseObject.TimeFadeIn;
double fadeOutDuration = baseObject.TimePreempt * OsuModHidden.FADE_OUT_DURATION_MULTIPLIER;
return (fadeOutStartTime + fadeOutDuration) - (baseObject.StartTime - baseObject.TimePreempt);
}
private static double getConstantRhythmNerfFactor(OsuDifficultyHitObject current)
{
// Studies [citation needed] suggest that 33bpm is where humans stop interpreting notes as a part of a beat,
// instead interpreting them as individual events. We're gonna use this to both lessen the nerf of this factor,
// as well as using it as a convenient limit for how back in time we're gonna look for the calculation.
const double time_limit = 1800;
const double time_limit_low = 500;
double constantRhythmCount = 0;
int index = 0;
double currentTimeGap = 0;
while (currentTimeGap < time_limit)
{
var loopObj = (OsuDifficultyHitObject)current.Previous(index);
if (loopObj.IsNull())
break;
double longIntervalFactor = Math.Clamp(1 - (loopObj.StrainTime - time_limit_low) / (time_limit - time_limit_low), 0, 1);
if (Math.Abs(current.StrainTime - loopObj.StrainTime) < 10) // constant rhythm, o-o-o-o
constantRhythmCount += 1.0 * longIntervalFactor;
else if (Math.Abs(current.StrainTime - loopObj.StrainTime * 2) < 10) // speed up rhythm, o---o-o
constantRhythmCount += 0.33 * longIntervalFactor;
else if (Math.Abs(current.StrainTime * 2 - loopObj.StrainTime) < 10) // slow down rhythm, o-o---o
constantRhythmCount += 0.33 * longIntervalFactor;
else
break;
currentTimeGap = current.StartTime - loopObj.StartTime;
index++;
}
double difficulty = Math.Pow(Math.Min(1, 2 / constantRhythmCount), 2);
return difficulty;
}
2022-10-08 03:26:56 +08:00
private static double getConstantAngleNerfFactor(OsuDifficultyHitObject current)
{
const double time_limit = 2000;
const double time_limit_low = 300;
double constantAngleCount = 0;
int index = 0;
double currentTimeGap = 0;
while (currentTimeGap < time_limit)
{
var loopObj = (OsuDifficultyHitObject)current.Previous(index);
if (loopObj.IsNull())
break;
double longIntervalFactor = Math.Clamp(1 - (loopObj.StrainTime - time_limit_low) / (time_limit - time_limit_low), 0, 1);
if (loopObj.Angle.IsNotNull() && current.Angle.IsNotNull())
{
double angleDifference = Math.Abs(current.Angle.Value - loopObj.Angle.Value);
constantAngleCount += Math.Cos(2 * Math.Min(Math.PI / 4, angleDifference)) * longIntervalFactor;
}
currentTimeGap = current.StartTime - loopObj.StartTime;
index++;
}
double difficulty = Math.Pow(Math.Min(1, 2 / constantAngleCount), 2);
return difficulty;
}
private static double getTimeNerfFactor(double deltaTime)
{
return Math.Clamp(2 - (deltaTime / 1500), 0, 1);
}
2022-06-21 15:54:27 +08:00
private static double logistic(double x) => 1 / (1 + Math.Pow(Math.E, -x));
}
}