52 lines
2.0 KiB
JavaScript
52 lines
2.0 KiB
JavaScript
/**
|
|
* DIAG (throwaway): inspect faction balance for a given galaxy seed.
|
|
*
|
|
* node dev/faction-balance.diag.mjs [SEED]
|
|
*/
|
|
process.env.NODE_ENV = 'dev';
|
|
|
|
import { pathToFileURL, fileURLToPath } from 'node:url';
|
|
import { dirname, join } from 'node:path';
|
|
|
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
|
|
const { config } = await import(pathToFileURL(join(__dirname, '../js/config/Config.js')).href);
|
|
const fs = await import('node:fs');
|
|
const dataDir = join(__dirname, '../data');
|
|
const configData = {};
|
|
for (const f of fs.readdirSync(dataDir)) {
|
|
if (!f.endsWith('.json') || f === 'manifest.json') continue;
|
|
configData[f.replace(/\.json$/i, '')] = JSON.parse(fs.readFileSync(join(dataDir, f), 'utf8'));
|
|
}
|
|
config.init(configData);
|
|
|
|
const { Galaxy } = await import(pathToFileURL(join(__dirname, '../js/galaxy/Galaxy.js')).href);
|
|
|
|
const seed = process.argv[2] ?? 'QB4UP8J5';
|
|
const g = Galaxy.create(seed);
|
|
const branchOf = g.jumpNetwork.branchOf;
|
|
const depth = g.jumpNetwork.depth;
|
|
const HOME = g.currentSystemId;
|
|
|
|
console.log(`seed=${seed} systems=${g.records.length} home=${HOME}`);
|
|
console.log('branches:', g.factions?.branches ?? null);
|
|
console.log('branchFaction:', g.factions?.branchFaction ?? null);
|
|
console.log('quota:', g.factions?.quota);
|
|
console.log('capitals:', g.factions?.capitals);
|
|
console.log('neutralCapital:', g.factions?.neutralCapital);
|
|
|
|
for (const b of g.factions?.branches ?? []) {
|
|
const nodes = [...branchOf.entries()].filter(([, x]) => x === b).map(([id]) => id);
|
|
const maxD = Math.max(1, ...nodes.map((id) => depth.get(id) ?? 1));
|
|
const elig = nodes.filter((id) => { const d = depth.get(id) ?? 0; return d >= 2 && d <= maxD - 1; });
|
|
console.log(` branch ${b}: nodes=${nodes.length} maxDepth=${maxD} eligible=${elig.length}`);
|
|
}
|
|
|
|
const counts = {};
|
|
for (const r of g.records) {
|
|
const f = r.faction ?? 'neutral';
|
|
counts[f] = (counts[f] ?? 0) + 1;
|
|
if (r.capital) console.log(` capital: ${r.id} (${r.capital}) faction=${r.faction}`);
|
|
}
|
|
console.log('faction system counts:', counts);
|