I'm checking if there is exactly 1 space (a path of 2 steps) between 2 locations. But I keep getting results where the positions are adjacent. This never used to happen and doesn't happen for all adjacent pathfinding, only some particular situations. I could use some kind of workaround but it would be a lot easier if the pathfinding results were reliable.
Silly_Sausage
@Silly_Sausage
Posts made by Silly_Sausage
-
RE: Pathfinding to adjacent positions
-
Pathfinding to adjacent positions
In simulation mode, I have placed a source right next to my spawn in any non-diagonal direction. The path found has two steps instead of one.
var spawn = Game.spawns.Spawn1; var source = spawn.pos.findClosest(FIND_SOURCES); var path = spawn.pos.findPathTo(source); console.log(path.length) // Output: 2
By placing sources in all 4 non-diagonal adjacent positions, the path will have 3 steps!
-
RE: Are path finding results cached?
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.
-
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. -
RE: Separating running/editting code
I think this would be nice to have, but keep in mind that switching your main program suddenly would be quite prone to errors itself. You'd have to maintain both programs constantly to make sure their memory usage is consistent or you might end up corrupting your AI state when you switch. But, you don't have much to lose if you run into a recurring error.
You can use a try-catch block but again there's a catch (no pun intended). You can't cancel the actions (creep moves, memory assignments, etc.) of your terminated program without throwing an error. And you can't set a memory flag to run a different program next tick unless you complete the tick without any errors. So again, you run the risk of corrupting your AI state.
I guess the only foolproof solution would be to use try-catch-finally blocks throughout your program to properly deal with errors.
-
Memory tab in editor popup not working properly.
Opening memory at the bottom of the screen while playing Screeps is working fine, but when I open a popup editor window and go into the memory tab I am having trouble viewing the memory watches.
The memory watches for rooms and spawn.Spawn1 (Which seem to automatically get added to my memory watches each time I start playing) show diagonal lines when I click them. Clicking on the Memory root object does nothing. But if I make my own memory watch and click on it, it works fine.
I have uploaded an image here:
http://imgur.com/tvHNYz6
(I think "Incorrect Memory Path" is just because I haven't added a spawn in the current game yet)