Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

251
Visualizações
Detección de islas: javascript

El problema

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!) producción

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.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda