// Lets the autopilot play five seeded games of up to three minutes and writes what happened to // metrics.json. The review pack shows these beside canon's: a rough measure of difficulty. import { writeFileSync } from "node:fs"; import { autopilot } from "../src/bot.js"; import { DT, createGame, start, step } from "../src/game.js"; const SEEDS = [1, 2, 3, 4, 5]; const LIMIT = 180; let saved = 0; let wrecked = 0; let survived = 0; for (const seed of SEEDS) { const game = start(createGame(seed)); let lives = game.lives; while (game.state === "play" && game.time < LIMIT) { step(game, autopilot(game), DT); if (game.lives < lives) { wrecked += lives - game.lives; lives = game.lives; } } saved += game.saved; survived += game.time; console.log( `seed ${seed}: saved ${game.saved}, ${game.state === "over" ? `lamp out at ${game.time.toFixed(0)} s` : "still lit"}`, ); } const n = SEEDS.length; const round = (x) => Math.round(x * 10) / 10; const metrics = { ships_saved: { value: round(saved / n), better: "higher" }, ships_wrecked: { value: round(wrecked / n), better: "lower" }, seconds_lit: { value: round(survived / n), unit: "s", better: "higher" }, }; writeFileSync("metrics.json", JSON.stringify(metrics, null, 2) + "\n"); console.log(JSON.stringify(metrics));