Pathfinder cannot find path within one room


  • Dev Team

    Feels like someone should write a detailed article about A* guts someday and explain the decisions behind default values. With gifs/pics and everything...

    But generally yes, @Tigga is right: pathfinding is a separate discipline of playing Screeps. Players are given the way of moving creeps which works good enough in most cases. But sometimes it happens that you must choose between pathing errors (which players can see) and stupidly high CPU consumption out of blue (which is much harder to find). Choosing the second would be... unwise.



  • There are awesome detailed articles by Red Blob Games:

    They are really helpful for understanding A*, tuning in-game PF and even implementing you own path-finding. Actually, built-in PF is pretty nice, but its parameters should be chosen carefully.



  • This post is deleted!


  • We still need a PathFinder.search specific write up.

    Some tidbits I've encountered over time:

    • It's not really A*, but jump point search.
      • what does that mean? I don't know, but I blame it every time it has unexpected behavior
    • The default heuristic of 1.2 finds non-optimal paths
      • 1 guarantees optimal but costs 50% more cpu.
    • Heuristic values above 10 or so screw with the algorithm and searches cost a lot more ops (though not a lot more CPU).
    • It will never produce a path that moves laterally on an exit tile
      • this is works well with exit tile teleportation
      • this interacts badly if you're movement constrained and on an exit tile. E.g you try to path a few tiles laterally will consume all ops and still produce an incomplete path.

  • Dev Team

    @deft-code yes we do, to remove some misunderstandings at least, for example:

    • It's not jump point search because JPS is exclusively for uniform-cost grids (as far as I know; if you know an article or something which proves otherwise, please post the link). So it's not really A* but not really JPS either.
    • The default heuristic is 1 which finds optimal paths


  • @o4kapuk, You're correct. JPS is only for uniform cost grids and is fairly well researched. I've never found a paper about our odd A*/JPS combo.

    Was the documentation incorrect or did you change the default heuristicWeight to 1?

    While looking for original Heurisitic weight I figured out why heuristicWeight values above 10 act funny. They're capped at 9 in the code. We should update the documentation. (Or remove the cap if it isn't needed).


  • Dev Team

    @deft-code The documentation was incorrect, now it's fixed.


  • Dev Team

    If you want to get some insights into the Screeps native PathFinder, the best way is to ask its author @The_General.



  • Luckily I know A* very well. But I always thought there are two implementations in screeps. One PathFinder written in C++ by General and a JS JPS version, which is the default in moveTo. The C++ PathFinder could be activated as default for moveTo by PathFinder.use(true), which is deprecated now. Did something change here? Is JPS still the default path finder or is it all PathFinder only now?



  • @xenofix said in Pathfinder cannot find path within one room:

    Luckily I know A* very well. But I always thought there are two implementations in screeps. One PathFinder written in C++ by General and a JS JPS version, which is the default in moveTo. The C++ PathFinder could be activated as default for moveTo by PathFinder.use(true), which is deprecated now. Did something change here? Is JPS still the default path finder or is it all PathFinder only now?

    It's been the PathFinder by default for everything for a few years now.


  • Dev Team

    @xenofix Native PathFinder is JPS too, and it is activated by default unless you call PathFinder.use(false).