recursion - Line and intersection based pathfinding -
recursion - Line and intersection based pathfinding -
i trying develop pathfinding algorithm finds closest path point tracing line initial position final position. test intersections obstacles ( of them in game rectangular ) , draw 2 new lines, 1 each of visible corners of obstacle. then, draw lines 2 corners endpoint , repeat intersection test each branch of path.
my question this: how propagate branching paths in lua without recursion? seems pretty easy recursion, don't want risk stack overflow , crash if path gets long.
if there technical term technique using, please tell me. own research when can.
there recursion , iteration. lua supports "infinite recursion" via tail calls, if can express recursion in terms of tail calls there no risk of stack overflow. example:
function f(x) if x==0 homecoming 0 end -- end recursion .... stuff ... homecoming f(x-1) end
section 6.3 of programming in lua (available online) discusses this.
if can't determine way tail calls have utilize iteration. illustration start 1 path, using while loop test how many intersections (exit loop when 0); loop calls function computes 2 new paths; each path added list; while loop in paths loop (since # of paths increases); path length can computed simultaneously; paths dead end , dropped; cyclical , should dropped; , rest arrive @ destination. maintain 1 shortest path or travel time (not same).
recursion lua line path-finding
Comments
Post a Comment