CablePilot / tools /run_headless.mjs
Edgar Moreau
Clear the playroom: cablepilot world model + MPPI in the browser
49ef597 verified
Raw History Blame Contribute Delete
1.02 kB
// node tools/run_headless.mjs [seconds] : run the mission without a page and print what happened (the smoke test).
import { readFileSync } from "node:fs";
import { loadModel } from "../core/model.js";
import { Mission } from "../core/mission.js";
const secs = +(process.argv[2] || 120);
const m = loadModel(JSON.parse(readFileSync(new URL("../core/model.json", import.meta.url))));
const mis = new Mission(m, 0);
let f, last = "";
const t0 = performance.now();
while (mis.t < secs) {
f = mis.step();
const ev = f.stats.events.at(-1);
if (ev && JSON.stringify(ev) !== last) { last = JSON.stringify(ev); console.log(`${ev.t.toFixed(1).padStart(6)} s ${ev.what}`); }
if (f.toys.every(t => t.state === "delivered")) break;
}
const wall = (performance.now() - t0) / 1000;
console.log(`\n${f.stats.delivered}/${f.toys.length} toys in ${f.t.toFixed(0)} s simulated, ${wall.toFixed(1)} s wall` +
` | ${f.stats.msPerPlan.toFixed(0)} ms per plan | furniture contact ticks ${f.stats.contacts} | phase ${f.phase}`);