This is what I have been using for sources. Can be important at low controller level.
accessPoints: function (room, pos) { var accessPoints = 0; if (room.lookForAt(LOOK_TERRAIN, pos.x+1, pos.y) != "wall") { accessPoints = accessPoints+1; } if (room.lookForAt(LOOK_TERRAIN, pos.x+1, pos.y+1) != "wall") { accessPoints = accessPoints+1; } if (room.lookForAt(LOOK_TERRAIN, pos.x+1, pos.y-1) != "wall") { accessPoints = accessPoints+1; } if (room.lookForAt(LOOK_TERRAIN, pos.x-1, pos.y) != "wall") { accessPoints = accessPoints+1; } if (room.lookForAt(LOOK_TERRAIN, pos.x-1, pos.y+1) != "wall") { accessPoints = accessPoints+1; } if (room.lookForAt(LOOK_TERRAIN, pos.x-1, pos.y-1) != "wall") { accessPoints = accessPoints+1; } if (room.lookForAt(LOOK_TERRAIN, pos.x, pos.y+1) != "wall") { accessPoints = accessPoints+1; } if (room.lookForAt(LOOK_TERRAIN, pos.x, pos.y-1) != "wall") { accessPoints = accessPoints+1; } return accessPoints; },
Yes there are several function to find distance between two targets. Cehck out http://support.screeps.com/hc/en-us/articles/207023879-PathFinder
By yes I mean you first find the path then check its length. Need to decide whether just doing a trigonometric distance is good enough.