evenfurther / pathfinding

Pathfinding library for rust
861 stars 71 forks source link

How to limit find steps? #609

Closed TheCGDF closed 1 month ago

TheCGDF commented 1 month ago

I'm using astar() but I find it does not have a parameter to stop finding when meet some conditions (and return None) ?

Is it possible to do it?

samueltardieu commented 1 month ago

The successors function is a FnMut and can capture a counter, you can use it to limit find steps. For example:

let mut steps = 0;   // steps will be captured in the lambda and will be incremented at each step
let successors = |n| {
  if steps > 100 { vec![] } else { steps += 1; real_successors_in_vec(n) }
}
let … = astar(…, successors, …);
…
TheCGDF commented 1 month ago

Okay, this is a solution.

Actually, I asked ChatGPT and he told me I must remove pathfinding and implement astar from zero by myself.🥲