I wasn't really sure where to put this so I decided her by default.
Also I'm not entirly sure how to ask the question I mean so I'll just try my best. How does the DF pathfinding work?
Some would say "imperfectly", but perhaps it's best to say "suboptimally" with a generous helping of "it
could be a lot worse".
As in, what kind of search algorithem, does it look at all the spaces next to each creature, then all the spaces next to those, and next to those or some other kind or magic?
As I understand it (from my largely passive/suggestions-only involvement in a certain Pathfinding Project of this parish) the current system uses the
A* algorithm for specific from/to routes, which I think you could arguably describe as a weighted hybrid between depth- and width-first searches.
However, when looking for "nearest <generic item>" (e.g. a new piece of stone to work at a workshop) when it starts off by taking coordinate differences (with apparent bias towards X-Y closeness, even with a multiple Z-difference, and never mind how long the actual path will be) and then calculating (by A*) the route to get there (or its impossibility, forcing it to moving onto the next possibility). That's rather than taking the route of a breadth-first search (or weighted equivalent) to find the actual nearest item.
And when searching for a position to work on a mining job (for example), it has a preference (I think: North, then South, West then East, then diagonals with in the same precedences) for where to stand to complete the job, regardless of whether the job could have been completed even by staying on the same square (and attacking from the SE) rather than finding a route all the way round the mountain to the tile (frexample) directly West of the to-be-mined tile to complete the tunnel. So that complicates matters.
As does the fact that a closed route is only reacted to once the agent finds itself at the blockage on the previously open route. Despite having omniscience in the original route-planning (even into bits of fortress they've never been in before, or across landscape so far unexplored by any other dwarf), they only re-route once their pre-planned route comes up against an apparently insurmountable obstacle, not dynamically when the closure first occurs. Or even (for transient routes, opening and closing via liquid flow or dynamic architectural features) waiting around for the route to open up again.
BICBW, YMMV. HTH, HAND.
(You see, I didn't know whether you were actually asking about how it comes up with the route (which is fairly optimal once calculated, but perhaps a little resource intensive in its derivation), or how it comes up with the end-point to any given route where multiple destinations are possible (definitely suboptimal, but once you know the tricks of the trade, can be accounted for and even exploited). So I think I've given you everything you might want to know, and eagerly await someone telling me that I'm plain wrong about something.