I am working on a project for my A.I. class and I have encountered a problem (which I recall having a few years ago on another project).
I don't know if this is a Lua or LOVE problem (most probably lua), you guys might be able to help...
I have the following local function:
Code: Select all
local function expand(tile)
-- Caso o tile for loja...
if tile.type ~= 'o' and tile.type ~= 'x' then
shops[tile.type] = shops[tile.type] + 1
elseif tile.type == 'x' then
return
end
tile.walkedOn = true
-- Table de tiles adjacentes
local adjTiles = {
self:getTile(tile.x + 1, tile.y),
self:getTile(tile.x - 1, tile.y),
self:getTile(tile.x, tile.y + 1),
self:getTile(tile.x, tile.y - 1)
}
-- Para cada tile (se existir e ainda não passou) expandir recursivamente
for i,v in ipairs(adjTiles) do
if v ~= nil and not v.walkedOn then
expand(v)
end
end
return
end
What happens is that it doesn't fully expand all tiles, the ones on the left and right hand side of my map (x = 1 and x = MAPSIZE) don't expand.
I tried changing the order of the tiles in "adjTiles" and that seems to change everything:
If I put "self:getTile(tile.x, tile.y - 1)" as first index, the right- and left-most tiles expand, but the top ones (y = 1) don't.
That happens with every permutation of adjTiles, some tiles don't expand.
A pic:
Thanks in advance!