mirror of
https://github.com/Azgaar/Fantasy-Map-Generator.git
synced 2025-12-17 01:41:22 +01:00
hasCoadjacentSameStateCells checks
This commit is contained in:
parent
b92c8b6ae9
commit
2327aa980c
3 changed files with 33 additions and 44 deletions
|
|
@ -6262,7 +6262,7 @@
|
||||||
<script src="libs/delaunator.min.js"></script>
|
<script src="libs/delaunator.min.js"></script>
|
||||||
|
|
||||||
<script src="utils/commonUtils.js"></script>
|
<script src="utils/commonUtils.js"></script>
|
||||||
<script src="utils/arrayUtils.js"></script>
|
<script src="utils/arrayUtils.js?v=14052022"></script>
|
||||||
<script src="utils/colorUtils.js"></script>
|
<script src="utils/colorUtils.js"></script>
|
||||||
<script src="utils/graphUtils.js"></script>
|
<script src="utils/graphUtils.js"></script>
|
||||||
<script src="utils/nodeUtils.js"></script>
|
<script src="utils/nodeUtils.js"></script>
|
||||||
|
|
@ -6280,7 +6280,7 @@
|
||||||
<script src="modules/lakes.js"></script>
|
<script src="modules/lakes.js"></script>
|
||||||
<script src="modules/names-generator.js"></script>
|
<script src="modules/names-generator.js"></script>
|
||||||
<script src="modules/cultures-generator.js"></script>
|
<script src="modules/cultures-generator.js"></script>
|
||||||
<script src="modules/burgs-and-states.js"></script>
|
<script src="modules/burgs-and-states.js?v=14052022"></script>
|
||||||
<script src="modules/routes-generator.js"></script>
|
<script src="modules/routes-generator.js"></script>
|
||||||
<script src="modules/religions-generator.js"></script>
|
<script src="modules/religions-generator.js"></script>
|
||||||
<script src="modules/military-generator.js"></script>
|
<script src="modules/military-generator.js"></script>
|
||||||
|
|
|
||||||
|
|
@ -496,25 +496,20 @@ window.BurgsAndStates = (function () {
|
||||||
paths.push([s.i, relaxed]);
|
paths.push([s.i, relaxed]);
|
||||||
|
|
||||||
function getHull(start, state, maxLake) {
|
function getHull(start, state, maxLake) {
|
||||||
const queue = [start],
|
const queue = [start];
|
||||||
hull = new Set();
|
const hull = new Set();
|
||||||
|
|
||||||
while (queue.length) {
|
while (queue.length) {
|
||||||
const q = queue.pop();
|
const q = queue.pop();
|
||||||
const nQ = cells.c[q].filter(c => cells.state[c] === state);
|
const sameStateNeibs = cells.c[q].filter(c => cells.state[c] === state);
|
||||||
|
|
||||||
cells.c[q].forEach(function (c, d) {
|
cells.c[q].forEach(function (c, d) {
|
||||||
const passableLake = features[cells.f[c]].type === "lake" && features[cells.f[c]].cells < maxLake;
|
const passableLake = features[cells.f[c]].type === "lake" && features[cells.f[c]].cells < maxLake;
|
||||||
if (cells.b[c] || (cells.state[c] !== state && !passableLake)) {
|
if (cells.b[c] || (cells.state[c] !== state && !passableLake)) return hull.add(cells.v[q][d]);
|
||||||
hull.add(cells.v[q][d]);
|
|
||||||
return;
|
const hasCoadjacentSameStateCells = sameStateNeibs.some(neib => cells.c[c].includes(neib));
|
||||||
}
|
if (hull.size > 20 && !hasCoadjacentSameStateCells && !passableLake) return hull.add(cells.v[q][d]);
|
||||||
const nC = cells.c[c].filter(n => cells.state[n] === state);
|
|
||||||
const intersected = common(nQ, nC).length;
|
|
||||||
if (hull.size > 20 && !intersected && !passableLake) {
|
|
||||||
hull.add(cells.v[q][d]);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (used[c]) return;
|
if (used[c]) return;
|
||||||
used[c] = 1;
|
used[c] = 1;
|
||||||
queue.push(c);
|
queue.push(c);
|
||||||
|
|
|
||||||
|
|
@ -6,45 +6,39 @@ function last(array) {
|
||||||
return array[array.length - 1];
|
return array[array.length - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
// return array of values common for both array a and array b
|
|
||||||
function common(a, b) {
|
|
||||||
const setB = new Set(b);
|
|
||||||
return [...new Set(a)].filter(a => setB.has(a));
|
|
||||||
}
|
|
||||||
|
|
||||||
function unique(array) {
|
function unique(array) {
|
||||||
return [...new Set(array)];
|
return [...new Set(array)];
|
||||||
}
|
}
|
||||||
|
|
||||||
// deep copy for Arrays (and other objects)
|
// deep copy for Arrays (and other objects)
|
||||||
function deepCopy(obj) {
|
function deepCopy(obj) {
|
||||||
const id = x=>x;
|
const id = x => x;
|
||||||
const dcTArray = a => a.map(id);
|
const dcTArray = a => a.map(id);
|
||||||
const dcObject = x => Object.fromEntries(Object.entries(x).map(([k,d])=>[k,dcAny(d)]));
|
const dcObject = x => Object.fromEntries(Object.entries(x).map(([k, d]) => [k, dcAny(d)]));
|
||||||
const dcAny = x => x instanceof Object ? (cf.get(x.constructor)||id)(x) : x;
|
const dcAny = x => (x instanceof Object ? (cf.get(x.constructor) || id)(x) : x);
|
||||||
// don't map keys, probably this is what we would expect
|
// don't map keys, probably this is what we would expect
|
||||||
const dcMapCore = m => [...m.entries()].map(([k,v])=>[k, dcAny(v)]);
|
const dcMapCore = m => [...m.entries()].map(([k, v]) => [k, dcAny(v)]);
|
||||||
|
|
||||||
const cf = new Map([
|
const cf = new Map([
|
||||||
[Int8Array, dcTArray],
|
[Int8Array, dcTArray],
|
||||||
[Uint8Array, dcTArray],
|
[Uint8Array, dcTArray],
|
||||||
[Uint8ClampedArray, dcTArray],
|
[Uint8ClampedArray, dcTArray],
|
||||||
[Int16Array, dcTArray],
|
[Int16Array, dcTArray],
|
||||||
[Uint16Array, dcTArray],
|
[Uint16Array, dcTArray],
|
||||||
[Int32Array, dcTArray],
|
[Int32Array, dcTArray],
|
||||||
[Uint32Array, dcTArray],
|
[Uint32Array, dcTArray],
|
||||||
[Float32Array, dcTArray],
|
[Float32Array, dcTArray],
|
||||||
[Float64Array, dcTArray],
|
[Float64Array, dcTArray],
|
||||||
[BigInt64Array, dcTArray],
|
[BigInt64Array, dcTArray],
|
||||||
[BigUint64Array, dcTArray],
|
[BigUint64Array, dcTArray],
|
||||||
[Map, m => new Map(dcMapCore(m))],
|
[Map, m => new Map(dcMapCore(m))],
|
||||||
[WeakMap, m => new WeakMap(dcMapCore(m))],
|
[WeakMap, m => new WeakMap(dcMapCore(m))],
|
||||||
[Array, a => a.map(dcAny)],
|
[Array, a => a.map(dcAny)],
|
||||||
[Set, s => [...s.values()].map(dcAny)],
|
[Set, s => [...s.values()].map(dcAny)],
|
||||||
[Date, d => new Date(d.getTime())],
|
[Date, d => new Date(d.getTime())],
|
||||||
[Object, dcObject],
|
[Object, dcObject]
|
||||||
// other types will be referenced
|
// other types will be referenced
|
||||||
// ... extend here to implement their custom deep copy
|
// ... extend here to implement their custom deep copy
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return dcAny(obj);
|
return dcAny(obj);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue