I'm trying to remove some drudgery: https://merveilles.town/@akkartik/112086504775924524
FKENDSMEJXEZPAT6K5TYJC2KZBVYKMXA7LN7ZVPZMYIBODWIB64AC function find_path(level, src, dst)local done = initialize_array(false, lh, lw)local cands = {}table.insert(cands, {x=src.x, y=src.y})while #cands > 0 dolocal cand = table.remove(cands, 1)local x,y = cand.x, cand.yif x == dst.x and y == dst.y then return cand endif y >= 1 and y <= lh and x >= 1 and x <= lw and not done[y][x] thendone[y][x] = truelocal curr = level[y][x]if curr ~= CELL_WALL and curr ~= CELL_CRATE and curr ~= CELL_CRATE_ON_TARGET thentable.insert(cands, {x=x-1, y=y, prev=cand})table.insert(cands, {x=x+1, y=y, prev=cand})table.insert(cands, {x=x, y=y-1, prev=cand})table.insert(cands, {x=x, y=y+1, prev=cand})end end end endfunction unwind_path(c)local result = {}while c dotable.insert(result, {x=c.x, y=c.y})c = c.prevendreturn resultendfunction draw_path(path)color(1,0,0)for _,cell in ipairs(path) dorect('line', left+(cell.x-1)*side, top+(cell.y-1)*side, side, side)end endfunction initialize_array(val, dim, ...)local result = {}local other_dims = {...}if #other_dims == 0 thenfor i=1,dim dotable.insert(result, val)endelsefor i=1,dim dotable.insert(result, initialize_array(val, ...))endendreturn resultend