const searchLoc = [ [-1,1], [0,1], [1,1], [-1,0], [1,0], [-1,-1],[0,-1],[1,-1] ] // Place Numbers export function mark(world) { for(let x = 0; x < world.dimensions[0]; x++){ for(let y = 0; y < world.dimensions[1]; y++){ if (world.data[x][y].type === 1) { var counter = 0; searchLoc.forEach(location => { const tempx = x + location[0] const tempy = y + location[1] if (tempx >= 0 && tempy >= 0 && tempx < world.dimensions[0] && tempy < world.dimensions[1]) { if (world.data[tempx][tempy].type === 5) { counter++; } } }); if (counter !== 0) { world.data[x][y].type = 15 + counter } } } } world.isMarked = true; return world; }