// 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; namespace osu.Game.Rulesets.Taiko.Difficulty.Preprocessing.Colour.Data { /// /// Encodes a list of s, grouped together by back and forth repetition of the same /// . Also stores the repetition interval between this and the previous . /// public class CoupledColourEncoding { /// /// Maximum amount of s to look back to find a repetition. /// private const int max_repetition_interval = 16; /// /// The s that are grouped together within this . /// public List Payload = new List(); /// /// The previous . This is used to determine the repetition interval. /// public CoupledColourEncoding? Previous = null; /// /// How many between the current and previous identical . /// If no repetition is found this will have a value of + 1. /// public int RepetitionInterval { get; private set; } = max_repetition_interval + 1; /// /// Returns true if other is considered a repetition of this encoding. This is true if other's first two payloads /// have identical mono lengths. /// private bool isRepetitionOf(CoupledColourEncoding other) { if (Payload.Count != other.Payload.Count) return false; for (int i = 0; i < Math.Min(Payload.Count, 2); i++) { if (!Payload[i].HasIdenticalMonoLength(other.Payload[i])) return false; } return true; } /// /// Finds the closest previous that has the identical . /// Interval is defined as the amount of chunks between the current and repeated encoding. /// public void FindRepetitionInterval() { if (Previous?.Previous == null) { RepetitionInterval = max_repetition_interval + 1; return; } CoupledColourEncoding? other = Previous.Previous; int interval = 2; while (interval < max_repetition_interval) { if (isRepetitionOf(other)) { RepetitionInterval = Math.Min(interval, max_repetition_interval); return; } other = other.Previous; if (other == null) break; ++interval; } RepetitionInterval = max_repetition_interval + 1; } } }