Standard Library
Pathfinding
A* and visibility over a grid of 0s (walkable) and truthy walls — the basis for the monster AI patterns above.
New to coding?
Copy the examples exactly first. Run them. Then change one number or word and run them again. You are not expected to memorize the command lists.
1
find_path & line_of_sight
Try this code
path = find_path(grid, sx, sy, ex, ey);
// -> list of [x, y] steps, start excluded, goal included
// -> [] if unreachable
visible = line_of_sight(grid, x1, y1, x2, y2);
// -> true if no wall lies on the straight line between the two cells