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.
2.4 kB · 38 lines
TypeScript
at main
123456789101112131415161718192021222324252627282930313233343536373839// The game moves in steps of a game minute (STEP), and the slower systems on their own clocks: both should play// the game as stepping sixty times a second, every system every step, did.import { test } from 'node:test';import assert from 'node:assert/strict';import { BUILDING } from '../src/world.ts';import { STEP, SLOW, due, loadGame, newGame, saveGame, seedRandom, setAuto, step, type State } from '../src/sim.ts';import { playGame } from '../scripts/play.ts';
test('a slow system is handed all the time since it last ran, about as often as it should run', () => { const S = newGame(BUILDING); for (const [key, every] of Object.entries(SLOW)) { let handed = 0, runs = 0; const n = 2000; for (let i = 0; i < n; i++) { const e = due(S, key, STEP); if (e) { handed += e; runs++; } } assert.ok(Math.abs(n * STEP - handed) <= every + 1e-6, `${key}: handed ${handed} of ${n * STEP}`); assert.ok(Math.abs(runs - (n * STEP) / every) <= 1, `${key}: ran ${runs} times`); } assert.equal(due(S, 'paper', 0.05), 0.05, 'a step finer than the game\'s runs everything');});
test('a late game plays the same in steps of a game minute as in sixtieths of a second with every system every step', () => { let saved = ''; playGame(true, 13, false, 0, (S: State) => { if (!saved && S.capability >= 150) saved = saveGame(S); }); // once training is under way assert.ok(saved, 'the bot got that far'); const run = (dt: number) => { seedRandom(5); const S = loadGame(BUILDING, saved)!, cap = S.capability, lost = S.machines.reduce((n, m) => n + m.missed, 0); setAuto(S, true); // with nobody to pick the next node, Auto does for (let t = 0; t < 120 - 1e-9; t += dt) step(S, dt); return { cap: S.capability - cap, lost: S.machines.reduce((n, m) => n + m.missed, 0) - lost, money: S.money, owned: S.machines.filter(m => m.owned).length }; }; const fine = run(1 / 60), coarse = run(STEP); assert.ok(fine.cap > 50, `it trains: ${fine.cap}`); assert.ok(Math.abs(coarse.cap - fine.cap) <= 0.1 * fine.cap, `capability gained: ${coarse.cap} in steps of a minute, ${fine.cap} in sixtieths`); assert.ok(Math.abs(coarse.money - fine.money) <= 0.05 * fine.money, `money: ${coarse.money} and ${fine.money}`); assert.ok(Math.abs(coarse.lost - fine.lost) <= 0.05 * fine.lost, `data lost: ${coarse.lost} and ${fine.lost}`); assert.equal(coarse.owned, fine.owned, 'and the same machines held');});