big cities to be capitals more often

This commit is contained in:
Azgaar 2021-08-11 21:37:36 +03:00
parent c71fed541e
commit ec14e09c14

View file

@ -34,7 +34,8 @@ window.BurgsAndStates = (function () {
let count = +regionsInput.value; let count = +regionsInput.value;
let burgs = [0]; let burgs = [0];
const score = new Int16Array(cells.s.map(s => s * Math.random())); // cell score for capitals placement const rand = () => 0.5 + Math.random() * 0.5;
const score = new Int16Array(cells.s.map(s => s * rand())); // cell score for capitals placement
const sorted = cells.i.filter(i => score[i] > 0 && cells.culture[i]).sort((a, b) => score[b] - score[a]); // filtered and sorted array of indexes const sorted = cells.i.filter(i => score[i] > 0 && cells.culture[i]).sort((a, b) => score[b] - score[a]); // filtered and sorted array of indexes
if (sorted.length < count * 10) { if (sorted.length < count * 10) {
@ -51,9 +52,8 @@ window.BurgsAndStates = (function () {
let spacing = (graphWidth + graphHeight) / 2 / count; // min distance between capitals let spacing = (graphWidth + graphHeight) / 2 / count; // min distance between capitals
for (let i = 0; burgs.length <= count; i++) { for (let i = 0; burgs.length <= count; i++) {
const cell = sorted[i], const cell = sorted[i];
x = cells.p[cell][0], const [x, y] = cells.p[cell];
y = cells.p[cell][1];
if (burgsTree.find(x, y, spacing) === undefined) { if (burgsTree.find(x, y, spacing) === undefined) {
burgs.push({cell, x, y}); burgs.push({cell, x, y});
@ -63,7 +63,9 @@ window.BurgsAndStates = (function () {
if (i === sorted.length - 1) { if (i === sorted.length - 1) {
WARN && console.warn("Cannot place capitals with current spacing. Trying again with reduced spacing"); WARN && console.warn("Cannot place capitals with current spacing. Trying again with reduced spacing");
burgsTree = d3.quadtree(); burgsTree = d3.quadtree();
(i = -1), (burgs = [0]), (spacing /= 1.2); i = -1;
burgs = [0];
spacing /= 1.2;
} }
} }