Hi,
I'm testing a random walk algorithm, it seems to be correct, but when I try to test it instanciating tiles, things go wrong. The game world is made of squared tiles, let's say 5x5 for testing:
[(-2, 0, -2), (-2, 0, -1), (-2, 0, 0), (-2, 0, 1), (-2, 0, 2), (-1, 0, -2), (-1, 0, -1), (-1, 0, 0), (-1, 0, 1), (-1, 0, 2), (0, 0, -2), (0, 0, -1), (0, 0, 0), (0, 0, 1), (0, 0, 2), (1, 0, -2), (1, 0, -1), (1, 0, 0), (1, 0, 1), (1, 0, 2), (2, 0, -2), (2, 0, -1), (2, 0, 0), (2, 0, 1), (2, 0, 2)]
A random walk of size 5 tiles has the following translations:
[(0, 0, 0), (-1, 0, 0), (-1, 0, -1), (-2, 0, -1), (-2, 0, -2)]
To see the result, I try to erase this translations from the previous array:
func erase_array_from_array(array : Array, erase : Array) -> Array:
array = array.duplicate()
for i in range(erase.size()):
array.erase(erase[i])
return array
So the tiles translations are:
[(-2, 0, 0), (-2, 0, 1), (-2, 0, 2), (-1, 0, -2), (-1, 0, 1), (-1, 0, 2), (0, 0, -2), (0, 0, -1), (0, 0, 1), (0, 0, 2), (1, 0, -2), (1, 0, -1), (1, 0, 0), (1, 0, 1), (1, 0, 2), (2, 0, -2), (2, 0, -1), (2, 0, 0), (2, 0, 1), (2, 0, 2)]
This seems to work. The problem is when instanciating the tiles:
var tile : Spatial
for i in range(tilesTranslations.size()):
tile = ASSETS3.EmptyTile.instance()
tile.translation = tilesTranslations[i]
add_child(tile)
And the result is:

Obviously, the result is wrong, since the tile at (0, 0, 0) shoudn't exists.
Full part of the code:
var tilesTranslations : Array = _generate_tiles_translations()
var walk = SECTOR_FUNCS.random_walk2(5, Vector3.ZERO, tilesTranslations)
print(tilesTranslations)
tilesTranslations = GEN_FUNCS.erase_array_from_array(tilesTranslations, walk)
print(tilesTranslations)
print(walk)
var tile : Spatial
for i in range(tilesTranslations.size()):
tile = ASSETS3.EmptyTile.instance()
tile.translation = tilesTranslations[i]
add_child(tile)