From 7c9fae55ad8b5aa2706f29800f91aacca11eedca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Sat, 22 Aug 2020 22:50:58 +0200 Subject: [PATCH] Hopefully fix off-by-one errors --- .../Preprocessing/StaminaCheeseDetector.cs | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/osu.Game.Rulesets.Taiko/Difficulty/Preprocessing/StaminaCheeseDetector.cs b/osu.Game.Rulesets.Taiko/Difficulty/Preprocessing/StaminaCheeseDetector.cs index 5187d101ac..d07bff4369 100644 --- a/osu.Game.Rulesets.Taiko/Difficulty/Preprocessing/StaminaCheeseDetector.cs +++ b/osu.Game.Rulesets.Taiko/Difficulty/Preprocessing/StaminaCheeseDetector.cs @@ -1,7 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using System; using System.Collections.Generic; using osu.Game.Rulesets.Difficulty.Utils; using osu.Game.Rulesets.Taiko.Objects; @@ -64,7 +63,10 @@ namespace osu.Game.Rulesets.Taiko.Difficulty.Preprocessing { var history = new LimitedCapacityQueue(2 * patternLength); - int repetitionStart = 0; + // for convenience, we're tracking the index of the item *before* our suspected repeat's start, + // as that index can be simply subtracted from the current index to get the number of elements in between + // without off-by-one errors + int indexBeforeLastRepeat = -1; for (int i = 0; i < hitObjects.Count; i++) { @@ -74,15 +76,18 @@ namespace osu.Game.Rulesets.Taiko.Difficulty.Preprocessing if (!containsPatternRepeat(history, patternLength)) { - repetitionStart = i - 2 * patternLength; + // we're setting this up for the next iteration, hence the +1. + // right here this index will point at the queue's front (oldest item), + // but that item is about to be popped next loop with an enqueue. + indexBeforeLastRepeat = i - history.Count + 1; continue; } - int repeatedLength = i - repetitionStart; + int repeatedLength = i - indexBeforeLastRepeat; if (repeatedLength < roll_min_repetitions) continue; - markObjectsAsCheese(repetitionStart, i); + markObjectsAsCheese(i, repeatedLength); } } @@ -119,17 +124,17 @@ namespace osu.Game.Rulesets.Taiko.Difficulty.Preprocessing if (tlLength < tl_min_repetitions) continue; - markObjectsAsCheese(Math.Max(0, i - tlLength), i); + markObjectsAsCheese(i, tlLength); } } /// - /// Marks all objects from index up until (exclusive) as . + /// Marks elements counting backwards from as . /// - private void markObjectsAsCheese(int start, int end) + private void markObjectsAsCheese(int end, int count) { - for (int i = start; i < end; ++i) - hitObjects[i].StaminaCheese = true; + for (int i = 0; i < count; ++i) + hitObjects[end - i].StaminaCheese = true; } } }