qiao / PathFinding.js

A comprehensive path-finding library for grid based games
http://qiao.github.io/PathFinding.js/visual/
8.35k stars 1.31k forks source link

Limit number of operations #117

Open Oza94 opened 8 years ago

Oza94 commented 8 years ago

Hello,

I wonder if there is a simple way to tell this lib to stop once it has reached a certain number of operations. I have a game where some maps are labyrinths and I don't want to calculate a full path if I reach a certain distance/complexity (the destination is considered "too far" to be reached in one pathfinding pass).

Regarding the actual implementation, this would need to update each finder to include this new parameter. Or maybe I'm missing something?

brean commented 6 years ago

It is possible, the implementation is quite trivial. I did this for the python implementation (see runs in keep_running that I call every time I iterate over the next node)

tukkek commented 5 years ago

It would also be great to allow the limit to be set not by total number of operations/iterations but thrrough maximum distance. For example: a certain unit can only move 6 steps this turn so whenever an ongoing calculation reaches more than 6 steps, drop that path.

It might be possible to achieve that by passing a virtual "reachable this turn" grid instead of the full grid but that's pretty inelegant.

Bingdom commented 1 year ago

Bumping this old thread- this is something that would benefit me too.

I have units in my game which will attempt to generate a path to the player (but may often be blocked by other units)- so it never finds a path and hence, can become computationally expensive.