Understanding the result of Room.serializePath()

  • Hello, So I finally decided to write my own path algorithm for the creeps, but I am having trouble understanding what does Room.serializePath return. I understand that it should return the following value format XXYYDDDDDDDDDD... But in my case XX and YY look like some random point around the start position.

    E.g. Room.serializePath(new RoomPosition(25, 25, "E33N45").findPathTo(new RoomPosition(25, 24, "E33N45"))) 25241 //Go TOP

    Room.serializePath(new RoomPosition(25, 25, "E33N45").findPathTo(new RoomPosition(25, 23, "E33N45"))) 242482 //Go TOP-LEFT TOP-RIGHT

    Room.serializePath(new RoomPosition(25, 25, "E33N45").findPathTo(new RoomPosition(25, 22, "E33N45"))) 2524111 //GO TOP TOP TOP

    Room.serializePath(new RoomPosition(25, 25, "E33N45").findPathTo(new RoomPosition(25, 21, "E33N45"))) 24248112 //GO LEFT-RIGHT TOP TOP TOP-RIGHT

    I understand the DDDDDDD values, but I expected XXYY to be the start location, but it is not. Am I missing something obvious here? Note: the path in my example is formed of plain terrain.

  • Why do you need to work with the raw string? You should be able to get your original path back using Room.deserializePath() and get the information from that.


  • You always can look into game engine: https://github.com/screeps/engine/blob/8928228bae60db78c50a7382cc3490c611b03f26/src/utils.js#L981

    Looks like first four characters is first position in path and then list of directions to the next position.

  • @jbyoshi Yes, that's true, In the end I realised that I don't need to work with the raw data. I was just confused when i looked at it and thought i need to fully understand it if I want to make use of it.

  • @flyasd1 That's great! It is now so obvious when i look at it, don't know why i didn't realised the output. Thanks for letting me know about the engine code, I wasn't aware you can view it, still learning.

  • The XXYY are the first tile in the path, rather than the starting point. So, basically, the right next time in the D direction from starting point.