Created
December 22, 2020 16:01
-
-
Save yatsuna827/3c931d17fabd536c43cf9039e0d1b022 to your computer and use it in GitHub Desktop.
FindSeedByBlink_naive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ほとんど変なことをせずに素直に処理を書いた場合. | |
// ただし瞬き閾値だけは『予め瞬きカウンタの値に対して閾値を計算しておく』『比較に使われる乱数は高々65536通りしかとらないので整数のまま扱う』という工夫をしている. | |
public static IEnumerable<uint> FindCurrentSeedByBlink_naive(uint seed, uint minIndex, uint maxIndex, int[] blinkInput, int allowanceLimitOfError = 20, int coolTime = 4) | |
{ | |
var res = new List<uint>(); | |
seed.Advance(minIndex); | |
blinkInput = blinkInput.Select(_ => _ - (5 + coolTime)).ToArray(); // 瞬き後のクールタイム分を引く. | |
var n = maxIndex - minIndex + 1; | |
// 『iフレーム目に1回目の瞬きが行われた』と仮定してシミュレート. | |
for (int i = 0; i < n; i++, seed.Advance()) | |
{ | |
var _seed = seed; | |
int index_of_input = 0; | |
for (; index_of_input < blinkInput.Length; index_of_input++) | |
{ | |
int blinkCounter = 0; | |
// 瞬きするまで進める. | |
while (_seed.GetRand() > BlinkConst.blinkThresholds_even[blinkCounter++]) { } | |
if (blinkInput[index_of_input] + allowanceLimitOfError < blinkCounter) break; // 許容誤差超過ならbreak. | |
if (blinkCounter < blinkInput[index_of_input] - allowanceLimitOfError) break; // 許容誤差未満ならbreak. | |
} | |
if (index_of_input == blinkInput.Length) res.Add(_seed); | |
} | |
return res.Distinct(); // 同じ結果を複数返さないようにしたいので. 十分なInputがあれば要素数はきわめて少ないので, ここを最適化する意味は薄い. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment