GetShuffledIndices function, to remove direction search bias
This commit is contained in:
parent
352535eaa2
commit
857e32e5fe
1 changed files with 17 additions and 0 deletions
17
src/Mono.cs
17
src/Mono.cs
|
@ -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[]
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue