Created
March 12, 2019 14:27
-
-
Save Liquidream/693602ee2c21c09e69a571aff9056734 to your computer and use it in GitHub Desktop.
Pathfinder... with diagonals?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- returns any neighbor map | |
-- position at which flag zero | |
-- is unset | |
function map_neighbors(node, graph) | |
local neighbors = {} | |
if (not fget(mget(node.x - 1, node.y - 1), 0)) add(neighbors, {x=node.x - 1, y=node.y - 1}) | |
if (not fget(mget(node.x, node.y - 1), 0)) add(neighbors, {x=node.x, y=node.y - 1}) | |
if (not fget(mget(node.x + 1, node.y - 1), 0)) add(neighbors, {x=node.x + 1, y=node.y - 1}) | |
if (not fget(mget(node.x - 1, node.y), 0)) add(neighbors, {x=node.x - 1, y=node.y}) | |
if (not fget(mget(node.x + 1, node.y), 0)) add(neighbors, {x=node.x + 1, y=node.y}) | |
if (not fget(mget(node.x - 1, node.y + 1), 0)) add(neighbors, {x=node.x - 1, y=node.y + 1}) | |
if (not fget(mget(node.x, node.y + 1), 0)) add(neighbors, {x=node.x, y=node.y + 1}) | |
if (not fget(mget(node.x + 1, node.y + 1), 0)) add(neighbors, {x=node.x + 1, y=node.y + 1}) | |
return neighbors | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment