wren/val Public Public: anyone can read this; nobody can change it.

forked from benjivers/val

workbenchthis machine
Files e7ab8b5cd8018f30a36edbeaab5c8b2644c60bcf
1
/**
2
 * The engine's body contract, checked against this game's own snapshot rather
3
 * than one a test made up: a game that renames `alive` passes every render
4
 * test and draws every enemy as a corpse. It lives here, not in `engine/`,
5
 * because it needs the game.
6
 */
7
8
import { expect, test } from "bun:test";
9
import { valGame } from "./arena.ts";
10
import { snapshotProblems } from "./engine/body.ts";
11
import { newMatch } from "./match.ts";
12
13
test("every body and `me` in a real snapshot of a running match fits the contract", () => {
14
  const state = newMatch(7);
15
  const game = valGame(state, () => {});
16
  for (let i = 0; i < 90; i++) game.step(state, 1 / 30);
17
  let bodies = 0;
18
  for (const viewer of state.players) {
19
    const seen = state.players.filter((p) => p.id === viewer.id || game.visible(state, viewer, p));
20
    const snap = game.snapshot(state, viewer, seen) as { me: unknown; players: unknown[] };
21
    expect(snapshotProblems(snap)).toEqual([]);
22
    bodies += snap.players.length;
23
  }
24
  expect(bodies).toBeGreaterThan(state.players.length);
25
});
↑↓ navigate ↵ open esc close
↑↓ navigate ↵ open esc close

Keyboard shortcuts