import assert from "node:assert/strict"; import { test } from "node:test"; import { autopilot } from "../src/bot.js"; import { LANTERN, createGame, simulate, start, step } from "../src/game.js"; test("the same seed plays the same game", () => { const a = simulate(start(createGame(9)), 20, autopilot); const b = simulate(start(createGame(9)), 20, autopilot); assert.equal(a.caught, b.caught); assert.equal(a.lives, b.lives); }); test("a spark over the lantern is caught, and one that falls past costs a life", () => { const game = start(createGame(1)); game.nextSpark = 999; game.sparks = [{ x: game.x, y: LANTERN.y - 2, vy: 200 }]; step(game); assert.equal(game.caught, 1); game.sparks = [{ x: 20, y: 549, vy: 200 }]; step(game); assert.equal(game.lives, 2); }); test("the game ends with the last life", () => { const game = start(createGame(1, { lives: 1 })); game.nextSpark = 999; game.sparks = [{ x: 20, y: 549, vy: 200 }]; step(game); assert.equal(game.state, "over"); });