/** * The engine's body contract, checked against this game's own snapshot rather * than one a test made up: a game that renames `alive` passes every render * test and draws every enemy as a corpse. It lives here, not in `engine/`, * because it needs the game. */ import { expect, test } from "bun:test"; import { valGame } from "./arena.ts"; import { snapshotProblems } from "./engine/body.ts"; import { newMatch } from "./match.ts"; test("every body and `me` in a real snapshot of a running match fits the contract", () => { const state = newMatch(7); const game = valGame(state, () => {}); for (let i = 0; i < 90; i++) game.step(state, 1 / 30); let bodies = 0; for (const viewer of state.players) { const seen = state.players.filter((p) => p.id === viewer.id || game.visible(state, viewer, p)); const snap = game.snapshot(state, viewer, seen) as { me: unknown; players: unknown[] }; expect(snapshotProblems(snap)).toEqual([]); bodies += snap.players.length; } expect(bodies).toBeGreaterThan(state.players.length); });