Bug in moveByPath



  • I believe I've found a bug in moveByPath using a serialized path. I made this simple test role to clarify the issue after arguing with it for several hours last night with a more complex script. 

    var roleMoveByPathTest = {
    run: function(creep) {
    let PATH = '252551111'
    if(!creep.memory.inPosition) {
    creep.moveTo(25,25);
    if (creep.pos.x == 25 && creep.pos.y == 25) {
    creep.memory.inPosition = true;
    console.log("(" + creep.pos.x+ "/" +creep.pos.y+ ")");
    }
    } else {
    var ERR = creep.moveByPath(PATH);
    if (ERR != (-5)) {
    console.log("(" +creep.pos.x+ "/" +creep.pos.y+ ")");
    }
    }
    }
    };

    module.exports = roleMoveByPathTest;

    Expected behavior would be for the creep to move down one, and then up four, finishing at 25,22. The creep instead drops the first move, and only executes the next four moves leaving it at 25,21 instead..


  • Culture

    TOP: 1,
    TOP_RIGHT: 2,
    RIGHT: 3,
    BOTTOM_RIGHT: 4,
    BOTTOM: 5,
    BOTTOM_LEFT: 6,
    LEFT: 7,
    TOP_LEFT: 8,

    These are the numbers corresponding to the directions.

    let PATH = '252551111'
    Implies, start at 25,25
    move 5 (bottom)
    Move 1 (top)
    Move 1 (top)
    Move 1 (top)
    Move 1 (top)

    What is the bug exactly?



  • the bug exactly, is that it doesn't move bottom. It ignores the first direction, and only executes the remaining 4.

     



  • which... I think I understand now.... I was misunderstanding how the serialized path is constructed slightly.

     

    252551111 does not mean start at 25,25 as one might naturally expect.

    It instead means start at 25,24 and move as follows.

     

    Move down (5) to 25,25

    Move up (1) to 25,24

    Move up (1) to 25,23

    Move up(1) to 25,22

    Move up(1), to 25,21

     

    Furthermore, it's smarter than one might expect for a simple serialized path, and will realize you are already at 25,25 and skip the first move accordingly.