From 857e32e5fedc540636c668e2c44fe3fbdba01684 Mon Sep 17 00:00:00 2001 From: spatialfree Date: Sun, 10 Nov 2024 03:35:36 -0500 Subject: [PATCH] GetShuffledIndices function, to remove direction search bias --- src/Mono.cs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/Mono.cs b/src/Mono.cs index 968971c..ddf72ca 100644 --- a/src/Mono.cs +++ b/src/Mono.cs @@ -248,6 +248,23 @@ static class Mono } } + static int[] GetShuffledIndices(T[] array) + { + int[] indices = new int[array.Length]; + for (int i = 0; i < array.Length; i++) + { + indices[i] = i; + } + for (int i = indices.Length - 1; i > 0; i--) + { + int j = System.Random.Shared.Next(i + 1); + int temp = indices[i]; + indices[i] = indices[j]; + indices[j] = temp; + } + return indices; + } + // directions for moving in the grid static readonly XYZi[] directions = new XYZi[] {