Are path finding results cached?



  • It seems like the results of path finding are cached and reused if repeated within the same tick. I have come across an interesting scenario.

    positions = [ ];
    for(i = 0; i < 2; i += 1) {
        path = startPos.findPathTo(target, {avoid: positions})
        step = path[path.length - 2];
        // positions = positions.concat();
        positions.push(room.getPositionAt(step.x, step.y));
    }
    

    The second iteration of the loop returns the same path as the first. I assume this is because it just returns a cached path. Adding in the commented line will solve the problem.
    Since concat returns a shallow copy, it's probably cheaper than modifying the caching to check if the avoid array has changed. But it would be helpful if the API docs mentioned the caching behavior and gave this solution.



  • cached path lives in creep.memory._move;



  • That's specifically for the moveTo function, to store a path between ticks. I'm talking about caching a path finding result for reuse within the same tick. I'm pretty sure it happens, but I don't think it's mentioned anywhere in the API docs.