SOURCE

var minPushBox = function(grid){
    var m = grid.length;
    var n = grid[0].length;
    var sx =-1,sy = -1, bx = -1, by = -1,tx = -1, ty = -1;
    for(let i = 0; i < m; i++){
        for(let j = 0; j < n; j++){
           if(grid[i][j] === 'S'){
               sx = i;
               sy = j;
           }else if(grid[i][j] === 'B'){
               bx = i;
               by = j;
           }else if(grid[i][j] === 'T'){
               tx = i;
               ty = j;
           }
        }
    }
    console.log(`人物坐标:${sx}, ${sy}`);
    console.log(`箱子坐标:${bx}, ${by}`);
    console.log(`目标坐标:${tx}, ${ty}`);

    var dirs = [[0,1],[0,-1],[1,0],[-1,0]];
    var queue = [];
    queue.push([bx,by]);
    while(queue.length){
        let arr = queue.shift();
        console.log('arr', arr);
        for(let i = 0; i < dirs.length; i++){
            let sx1 = arr[0] + dirs[i][0];
            let sy1 = arr[1] + dirs[i][1]
            console.log(`${sx1}, ${sy1}`);
        }
    }

};


var grid =  [["#","#","#","#","#","#"],
             ["#","T","#","#","#","#"],
             ["#",".",".","B",".","#"],
             ["#",".","#","#",".","#"],
             ["#",".",".",".","S","#"],
             ["#","#","#","#","#","#"]];
minPushBox(grid);
console 命令行工具 X clear

                    
>
console