Play Home Contribute Github Join Us! Discourse Staff Members Github Contribution Guides Team

SleepWalkers [HELP]

my code works so far but the hero only builds one wall. any help will be greatly appreciated.

var hunter = hero.findNearest(hero.findFriends());
var fenceMap = hunter.getMap();

// This function converts grid into XY coordinates.
function convertCoor(row, col) {
    return {x: 34 + col * 4, y: 26 + row * 4};
}


// Iterate over fenceMap and build at fence at all 1s.
for(var j = 0; j < fenceMap.length; j++) {
    for(var i = 0; i<fenceMap.length; i++){
        if(i && j == 1){
            var coor = convertCoor(i,j);
            hero.buildXY("fence", coor.x, coor.y);
        }
    }
}
// Move back to the village after building the fences.
hero.moveXY(22, 15);

Keep in mind that you are checking the fenceMap grid coordinates for the ā€œ1ā€™sā€. Right now you are only comparing the index variables to 1.

if(i && j == 1)  //  check fenceMap with both variables  i and j in the array to compare against 1

I like to think of battleship on this one with fenceMap being the grid, with i and j the X, Y coordinates and 1 is their ship.

ok. thanks. ill try this and see if it works.:+1:

1 Like