Published
Edited
Dec 8, 2021
Insert cell
Insert cell
Insert cell
newGameWorld = [...givenAreas, ...firstFreeArea]
Insert cell
Insert cell
firstFreeArea = findFreeArea([...givenAreas])
Insert cell
Insert cell
Insert cell
Insert cell
findFreeArea = function( areas) {
const firstFreeArea = [];
for( const area of areas) {
const neighbours = h3.kRing( area, 1); // 6-7 neighbours, including the origin area
const freeNeighbour = neighbours.find(( neighbour, i) => {
return i > 0 // omit origin area, which is included by kRing (at k-ring 0)
&& !areas.includes( neighbour); // neighbour should not match any other area
});
if( freeNeighbour) {
firstFreeArea.push( freeNeighbour);
break;
}
}
return firstFreeArea;
}
Insert cell
Insert cell
Insert cell
Insert cell
import { H3MiniMap, h3 } from "@olange/h3-minimap"
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more