Estoy haciendo un generador de islas javascript usando el algoritmo DFS, pero me encontré con un problema. Quiero detectar la posición y el área de cada isla, y no todos los puntos que se encuentran dentro de la isla. Crea una nueva isla para cada coordenada sobre el nivel del mar. Aquí está mi código:
// recursive function to check the island's size checkIsland(island, x, y){ if (this.terrain.getHeightFromMap(x, y) >= 3) { island.size++; if (x > 0) { this.checkIsland(island, x - 1, y); this.matrix[`${x - 1}:${y}`] = 1; } if (x < this.terrain.length - 1) { this.checkIsland(island, x + 1, y); this.matrix[`${x + 1}:${y}`] = 1; } if (y > 0) { this.checkIsland(island, x, y - 1); this.matrix[`${x}:${y - 1}`] = 1; } if (y < this.terrain.length - 1) { this.checkIsland(island, x, y + 1); this.matrix[`${x}:${y + 1}`] = 1; } // update the matrix this.matrix[`${x}:${y}`] = 1; } } update(){ this.campos = [Math.round(this.camera.position.x), Math.round(this.camera.position.y), Math.round(this.camera.position.z)]; for (var x = -10+this.campos[0]; x < 10+this.campos[0]; x++) { for (var y = -10+this.campos[2]; y < 10+this.campos[2]; y++) { if(this.matrix[`${x}:${y}`] == undefined){ let island = Object.assign({}, island_example); island.position = [x, y]; this.checkIsland(island, x, y); if(island.size > 1){ this.islands.push(island); } } } } for(var i in this.islands){ let _ = BABYLON.MeshBuilder.CreatePlane("quad", {width: 10, height: 10}, this.scene); _.position.y = this.terrain.getHeightFromMap(this.islands[i].position[0], this.islands[i].position[1]) + 1; _.position.x = this.islands[i].position[0]; _.position.z = this.islands[i].position[1]; // remove the island from the list if(this.islands[i].size < 10){ this.islands.splice(i, 1); } } } Salida: (Advertencia: ¡Retrasa el navegador!) 
Salida esperada: (Detalles de una isla) Una única coordenada 2d que indica la posición del centro de la isla y el área de la isla.