fuzzyworld

explodorama / files / test / replayCompare.test.ts

replayCompare.test.ts

Blame: the commit that last changed each line · file · history

351348d1 2026-11-04 Pavel Safronov1import { describe, expect, it } from 'vitest'
2import { readFileSync } from 'node:fs'
3import { buildReplay } from '../src/sim/replayCompare'
4import { replay } from '../src/sim/record'
5import type { RunRecord } from '../src/sim/record'
6import { step } from '../src/sim/turn'
7
8/** The report of Q101 (seed 1464004408, level 4): the autopilot, with Bomb Pass, walked into its own bomb's blast. */
9const record = JSON.parse(readFileSync(new URL('./fixtures/q101-bomb-pass.json', import.meta.url), 'utf8')) as RunRecord
10
11describe('the report replay (Q103)', () => {
12 const script = buildReplay(record)
13
14 it('starts a few turns before the autopilot took over, on the report\'s level', () => {
15 expect(script.level).toBe(4)
16 expect(script.prefix.length).toBe(6)
17 let s = script.start
18 for (const a of script.prefix) s = step(s, a).state
19 expect(s.enemies).toHaveLength(0)
20 // The report went on 3 turns past that moment, then waits.
21 expect(script.old.slice(0, 3)).toEqual(record.actions.slice(-3))
22 })
23
24 it('shows today\'s autopilot keeping its life where the report lost one', () => {
25 expect(script.oldEnd.lives).toBeLessThan(script.newEnd.lives)
26 expect(script.newEnd.lives).toBe(replay({ ...record, actions: record.actions.slice(0, 287) }).lives)
27 })
28
29 it('runs with the rules of today', () => {
30 expect(script.versionMismatch).toBe(false)
31 })
32})