GetShuffledIndices function, to remove direction search bias

This commit is contained in:
ethan merchant 2024-11-10 03:35:36 -05:00
parent 352535eaa2
commit 857e32e5fe

View file

@ -248,6 +248,23 @@ static class Mono
} }
} }
static int[] GetShuffledIndices<T>(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 // directions for moving in the grid
static readonly XYZi[] directions = new XYZi[] static readonly XYZi[] directions = new XYZi[]
{ {