-
What do you want to achieve? Each tile has 4 neighbors. +1,-1,+9,-9. I want it to give me all the neighbors of set tile (ie: 15 → 16,14,6,24
-
What is the issue? The problem with this is when i get to a tile thats on the border (ie: 18) the neighbors are 17,19,9,27 but 19 is on the other side of the grid meaning its not a neighbor.
Heres a picture to show what I’m talking about (this is on a 10x10 grid but same concept):
local gridSize = 9^2
local grid = {}
for i = 1,gridSize do
table.insert(grid,i)
end
local function getNeighbors(tile,grid)
local neighbors = {
tile + 1;
tile - 1;
tile + 9;
tile - 9;
}
for _,neighbor in ipairs(neighbors) do
--check if its in the grid
if neighbor >= 1 and neighbor <= gridSize then
--detect if its a neighbor
???
end
end
end