Skip to content

Instantly share code, notes, and snippets.

@Liquidream
Created March 12, 2019 14:27
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Liquidream/693602ee2c21c09e69a571aff9056734 to your computer and use it in GitHub Desktop.
Save Liquidream/693602ee2c21c09e69a571aff9056734 to your computer and use it in GitHub Desktop.
Pathfinder... with diagonals?
-- 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