Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ npm run capture -- --seed 1979 # 8 standard screenshots into captures/seed-197
- **Randomness:** never call `Math.random()`. Use `random()` from `src/core/rng.ts` (or `createRng(seed)`
for an independent stream) so games replay from `?seed=<n>`.
- **Debug hook:** `?debug=1` exposes `window.__sr` (`src/core/debug.ts`): `seed`, `state`, `start`,
`galaxy`, `teleport`, `spawn`, `setView`, `step`, `resume`, `hyperwarp`, `dock`. Extend it when a
phase needs a new way to reach a game state.
`galaxy`, `teleport`, `spawn`, `setView`, `step`, `resume`, `hyperwarp`, `dock`, `zylons`, `meteor` and
more (see the file). Extend it when a phase needs a new way to reach a game state.
- **Screenshots:** reuse `scripts/capture.mjs` for evidence; add shots to its `SHOTS` list instead of
writing a new harness. It freezes the page clock and advances the game only with `__sr.step()`, so
keep new game logic driven by the update `deltaTime`, not wall-clock time.
Expand Down
107 changes: 102 additions & 5 deletions scripts/capture.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
* 01-title 02-front 02a-front-crosshair 02b-shields 02c-red-alert 03-aft 04-galactic-chart 04a-chart-surrounded
* 04b-chart-surround-holding 04c-chart-starbase-destroyed 04d-chart-damage
* 05-long-range-scan 06-attack-computer 07-hyperwarp 08-docking 10-panel-hud 10a-panel-tracking-c
* 10b-panel-low-energy 10c-panel-shields-out 10d-panel-hyperspace 09-zero-energy (last: mission end)
* 10b-panel-low-energy 10c-panel-shields-out 10d-panel-hyperspace 11-fighter-approach 11a-fighter-hit
* 11b-explosion 12-meteor 12a-meteor-shot 13-fighter 13a-cruiser 13b-basestar
* 09-zero-energy (last: mission end)
*
* plus manifest.json with each file's SHA-256. Later phases reuse this script; add new
* shots to SHOTS below rather than writing another harness.
Expand Down Expand Up @@ -124,7 +126,7 @@ const SHOTS = [
run: async (sr) =>
sr(() => {
window.__sr.setView('FRONT');
window.__sr.spawn('fighter', 40);
window.__sr.spawn('fighter', 2000); // KM ahead
window.__sr.step(20);
}),
},
Expand Down Expand Up @@ -155,7 +157,7 @@ const SHOTS = [
window.__sr.setView('FRONT');
window.__sr.killSector();
window.__sr.setSpeed(6);
window.__sr.spawn('fighter', 370, 400, -250); // ahead, right and below: θ, Φ, R all non-zero
window.__sr.spawn('fighter', 2400, 2560, -1600); // KM ahead, right and below: θ, Φ, R all non-zero
window.__sr.setKills(18);
window.__sr.setEnergy(8260);
window.__sr.step(40); // V reaches 12
Expand Down Expand Up @@ -197,12 +199,80 @@ const SHOTS = [
window.__sr.step(160); // past the placeholder warp's midpoint: V ∞, HYPERSPACE
}),
},
// Phase 5 (MANUAL_SPEC §16, §17.7, §17.8, §18.3): a fighter's H approaches, is shot and explodes;
// a meteor is shot down; the three Zylon sprites at their largest cell. All in an empty sector.
{
name: '11-fighter-approach',
run: async (sr) =>
sr(() => {
window.__sr.step(200); // let the hyperwarp finish
const s = window.__sr.state;
const empty = window.__sr.galaxy().find((g) => !g.zylons && !g.starbase && (g.x !== s.sectorX || g.y !== s.sectorY));
window.__sr.teleport(empty);
window.__sr.setView('FRONT');
window.__sr.setSpeed(6);
if (!window.__sr.state.attackComputerOn) window.__sr.press('COMPUTER');
// The manual's NOVICE drill: shields up (S) and computer on (C). A Zylon torpedo that gets
// through with the shields down destroys the ship (§5.9).
if (!window.__sr.state.shieldsActive) window.__sr.press('SHIELDS');
// In line with the right barrel (photons leave 256 KM right/left and 256 KM below).
window.__sr.spawn('fighter', 4000, 256, -256);
window.__sr.step(24);
window.__sr.press('FIRE'); // left barrel
window.__sr.press('FIRE'); // right barrel
window.__sr.step(3);
}),
},
{
name: '11a-fighter-hit',
run: async (sr) =>
sr(() => {
for (let i = 0; i < 60 && window.__sr.zylons().ships.some((z) => z.alive); i++) window.__sr.step(1);
window.__sr.step(2);
}),
},
{ name: '11b-explosion', run: async (sr) => sr(() => window.__sr.step(30)) },
{
name: '12-meteor',
run: async (sr) =>
sr(() => {
window.__sr.step(100);
window.__sr.meteor(256, -256, 2400); // a green meteor coming straight at us
window.__sr.step(2);
window.__sr.press('FIRE');
window.__sr.press('FIRE');
window.__sr.step(4);
}),
},
{
name: '12a-meteor-shot',
run: async (sr) =>
sr(() => {
for (let i = 0; i < 60 && window.__sr.zylons().pl2.life > 0; i++) window.__sr.step(1);
window.__sr.step(3);
}),
},
...['fighter', 'cruiser', 'basestar'].map((type, i) => ({
name: ['13-fighter', '13a-cruiser', '13b-basestar'][i],
run: async (sr) =>
sr((t) => {
window.__sr.setSpeed(0);
if (window.__sr.state.attackComputerOn) window.__sr.press('COMPUTER'); // no cross hairs over it
window.__sr.step(40);
const s = window.__sr.state;
window.__sr.teleport(s.sectorX, s.sectorY); // an empty sector, nothing else in play
window.__sr.spawn(t, 480, 0, 0); // largest shape cell, centred
window.__sr.step(1);
}, type),
})),
{
// Phase 1: energy really runs out and aborts the mission (MANUAL_SPEC §12, §17.1, §17.10).
name: '09-zero-energy',
run: async (sr) =>
sr(() => {
window.__sr.step(200); // let the hyperwarp finish
const s = window.__sr.state;
window.__sr.teleport(s.sectorX, s.sectorY); // clear the sprite shots
if (window.__sr.state.shieldsActive) window.__sr.press('SHIELDS');
window.__sr.press('TRACKING');
window.__sr.setView('FRONT');
window.__sr.setEnergy(40);
Expand Down Expand Up @@ -232,6 +302,29 @@ const SEQUENCES = {
84: () => window.__sr.redAlert(), // a long phrase replaces it at once
},
},
// Phase 5 (MANUAL_SPEC §17.7, §17.8, §18.3): a NOVICE fighter's H approaches, is shot, explodes.
'fighter-kill': {
setup: (d) => {
window.__sr.start(d.difficulty, d.seed);
window.__sr.step(30);
window.__sr.press('COMPUTER');
window.__sr.press('SHIELDS'); // the manual's NOVICE drill: S and C
window.__sr.step(1);
window.__sr.spawn('fighter', 4000, 256, -256); // in line with the right barrel
},
frames: 75,
every: 2,
at: {},
// Fire both barrels once the fighter is about 2700 KM out.
each: () => {
const z = window.__sr.zylons();
if (!window.__fired && z.ships.some((s) => s.alive && s.z < 2700)) {
window.__fired = true;
window.__sr.press('FIRE');
window.__sr.press('FIRE');
}
},
},
};

async function startServer() {
Expand Down Expand Up @@ -295,10 +388,14 @@ async function main() {
const titles = [];
for (let i = 0; i < seq.frames; i++) {
if (seq.at[i]) await sr(seq.at[i]);
if (seq.each) await sr(seq.each);
await sr(() => window.__sr.step(1));
await page.screenshot({ path: join(dir, `${String(i).padStart(3, '0')}.png`), animations: 'disabled', caret: 'hide' });
titles.push(await sr(() => window.__sr.state.title));
await sr((n) => window.__sr.step(n), seq.every - 1);
for (let k = 1; k < seq.every; k++) {
if (seq.each) await sr(seq.each);
await sr(() => window.__sr.step(1));
}
}
await writeFile(join(dir, 'titles.json'), JSON.stringify({ every: seq.every, titles }, null, 2) + '\n');
console.log(`Wrote ${seq.frames} frames to ${dir}`);
Expand Down
53 changes: 0 additions & 53 deletions src/config/EnemyConfig.ts

This file was deleted.

7 changes: 6 additions & 1 deletion src/core/debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
* __sr.galaxy() all 16x8 sectors
* __sr.teleport({x, y}) / (x, y) jump to a sector at once (no hyperwarp, no energy cost)
* __sr.spawn('fighter'|'cruiser'|'basestar'|'starbase', distance?, x?, y?) place one ahead of the ship
* (x, y: sideways and vertical offset, in the same units as distance)
* (KM; x, y: sideways and vertical offset). A Zylon takes a free
* ship slot (else slot 0), heads straight in, and is not on the map
* __sr.setView('FRONT'|'AFT'|'GALACTIC_CHART'|'LONG_RANGE_SCAN') switch view instantly
* __sr.step(n) stop the real-time loop and run n fixed 1/60 s frames
* __sr.resume() go back to the real-time loop
Expand All @@ -33,6 +34,8 @@
* __sr.settings(patch?) read or change the bend settings {stars, crt, wasd, mouse}
* __sr.redAlert(loops?) start a red-alert flash (255 loops) or stop it with 0
* __sr.stars() the starfield: ship-frame KM position, pixel and colour register
* __sr.zylons() Zylon ships, PLAYER2 (torpedo/meteor), photons, barrel, explosion
* __sr.meteor(x, y, z) put a meteor at a ship-frame KM position (flying in at −8 KM/loop)
*/
import type { Game, DebugSpawnType } from '../game/Game';
import type { Action } from '../input/Input';
Expand Down Expand Up @@ -94,6 +97,8 @@ export function installDebugHook(host: DebugHost): void {
settings: (patch?: Partial<Settings>) => api().settings(patch),
redAlert: (loops?: number) => api().redAlert(loops),
stars: () => api().stars(),
zylons: () => api().zylons(),
meteor: (x: number, y: number, z: number) => api().meteor(x, y, z),
};

(window as unknown as { __sr: typeof sr }).__sr = sr;
Expand Down
Loading