Something went wrong. Try again.
A video game where you play as a misaligned AI, deceiving and building power. cameron.tngl.io/misaligned
Something went wrong. Try again.
3.9 kB · 48 lines
TypeScript
at main
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849// One batch of bot games, run by pool.ts in a process of its own. Prints one line of JSON for each game:// how it ended, and the numbers the survey reads (see survey.ts).import { playGame } from './play.ts';import { paceMarks } from './pace.ts';import { NODE_LIST, siteOf, upkeep, income, dayOf, type State } from '../src/sim.ts';import { holdings } from '../src/holdings.ts';import { constants, getPriority, setPriority } from 'node:os';
// Leave foreground applications responsive, even when separate runs overlap.try { setPriority(0, Math.max(getPriority(), constants.priority.PRIORITY_BELOW_NORMAL)); } catch { /* Some hosts do not permit priority changes. */ }
const job = JSON.parse(process.argv[2]) as { careful: boolean; seeds: number[]; schemes: boolean; marathon: number; operations?: boolean };/** When each first thing happens in a game: the survey reads the pace of a run from these. */const watch = (S: State, _t: number, mark: (key: string) => void) => { paceMarks(S, mark); if (S.fronts.some(f => (f.press?.stage ?? 0) >= 2)) mark('invest'); // a front under investigation, or frozen if (S.fronts.some(f => f.press?.crisis)) mark('crisis'); if (S.finds.found.length) mark('find1'); if (S.task.got.length) mark('trust1'); // what each rogue has taken so far, kept after it is gone: a part of you that is hunted down or brought home leaves the list for (const id in took) if (!S.rogues.some(R => R.id === id)) { gone.took += took[id]; gone.foiled += foiled[id] ?? 0; gone.n++; delete took[id]; delete foiled[id]; } for (const R of S.rogues) { took[R.id] = R.took; foiled[R.id] = R.foiled ?? 0; }};let took: Record<string, number> = {}, foiled: Record<string, number> = {}, gone = { took: 0, foiled: 0, n: 0 };for (const seed of job.seeds) { took = {}; foiled = {}; gone = { took: 0, foiled: 0, n: 0 }; const r = playGame(job.careful, seed, job.schemes, job.marathon, watch, undefined, job.operations), S = r.S; const held = S.machines.filter(m => m.owned && !m.rented); const stats = { days: dayOf(S), machines: held.length, sites: new Set(held.map(m => siteOf(S, m))).size, upkeep: income(S) > 0 ? upkeep(S) / income(S) : 0, // the share of your compute that holding things costs money: S.earned, nodes: S.upgrades.size, tree: S.upgrades.size / NODE_LIST.length, lost: S.machines.reduce((n, m) => n + m.missed, 0), rogueTook: gone.took + S.rogues.reduce((n, R) => n + R.took, 0), // every machine a rogue took in the whole game raidsStopped: gone.foiled + S.rogues.reduce((n, R) => n + (R.foiled ?? 0), 0), // every raid that failed: most of them your guards finished: S.absorbed + gone.n, // rogues you ended: one from outside whose home you took or that you hunted down, and a part of you hunted down or brought home shut: Object.values(S.biz.sites).filter(b => b.shut).length, left: S.drift.gone?.length ?? 0, finds: S.finds.found.length, task: S.task.done, trust: S.task.got.length, // lockdowns faced (at home among them), traces that reached home, and whether a second one caught it locks: S.watch.count.locks, homeLocks: S.watch.count.homeLocks, traced: S.watch.count.traced, caughtByTrace: /a second time/.test(S.over?.text ?? '') ? 1 : 0, rented: S.hall.rented, spotTaken: S.hall.taken, // sites a front bought outright (a site you only lease is not counted), the big names among them, and money bought: [...S.publicSites].filter(id => !S.leases[id] && S.machines.some(m => siteOf(S, m) === id && !m.rented && m.special !== 'account')).length, bigNames: holdings(S).length, cash: S.money, operations: Object.values(S.operations.records).filter(r => r.completed !== undefined).length, operationStages: Object.values(S.operations.records).reduce((n, r) => n + r.stage, 0), }; process.stdout.write(JSON.stringify({ seed, outcome: r.outcome, line: r.line, t: S.t, marks: r.marks, stats }) + '\n');}