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
47 changes: 47 additions & 0 deletions phaser-asteroids/docs/gameplay-experiment-a.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Gameplay experiment A (local only)

Historical record of the approved A baseline. Experiment B now adds explosions on top of these settings;
see `gameplay-experiment-b.md` for current behavior and the combined ranked reference result.

Rules `1.1.0`, replay schema still `1`. Initial values:

| Setting | Previous | Experiment |
| --- | --- | --- |
| Ordinary asteroid drop roll (after failed Mega roll) | 8% | 12% |
| Mega Power roll | 1.5% | 1.5%, unchanged |
| Armored unlock | 45 s | 25 s |
| Volatile unlock / relative spawn weight | 120 s / 0 | 60 s / 0.12 |
| Small UFO chance per scheduled spawn | 0% until 120 s | 10% from 60 s |

The existing later small-UFO steps remain 20% at 120 s, 40% at 240 s and 60% at 360 s.
Volatile's normalized share after unlocking is `0.12 / (1 + 0.35 + 0.12)`, about 8.2% of new asteroid
spawn attempts; children inherit the existing archetype rules. Edge spawning/culling is unchanged.
Drop chance including Mega is `0.015 + 0.985 * 0.12 = 13.32%` per eligible asteroid destruction.
Types, durations, UFO cadence/cap/AI, health, visuals, scoring and controls are unchanged. No explosions.

Play on the Vite development server (`http://127.0.0.1:5173/`), selecting **PLAY** / Space on desktop
or **PRACTICE** on mobile for local play without a ranked backend. If the server is stopped, run
`npm run dev -- --host 127.0.0.1 --port 5173`.
Around 25 s armored rocks become eligible; around 60 s volatile rocks and occasional small UFOs become
eligible. Unlocks do not force immediate encounters: the next scheduled spawn and random roll still apply.

## Ranked release implications

Spawn/drop changes alter RNG consumption and simulation outcomes. Both client and Worker import the same
rules constant and core simulation; neither old replays nor old clients should be treated as compatible.
The local client rejects a live `1.0.0` challenge, and the `1.1.0` server rejects runs issued under `1.0.0`.
The verifier supports only the currently deployed rules, with no backward simulation implementation.

If the experiment is approved, the simplest safe approach is a coordinated frontend/Worker release under
`1.1.0`, with a planned ranked maintenance/cutover window that drains active old-rules runs first and
asks players to refresh. A staggered rollout will temporarily reject mismatched clients; outstanding old
run tokens cannot be verified after the Worker upgrade. Decide that release procedure separately.

Scores are not directly comparable across these balance rules even though point formulas are unchanged.
Existing leaderboard queries already filter by current rules version, so old rows remain stored but are
excluded from the new all-time/weekly rankings. No database reset or data migration is needed; historical
board browsing is not implemented by this experiment. No production data or deployment was changed.

The fixed-seed server test's genuine completed run now earns 7884 (previously 9114), illustrating why old
and new results must stay separate. Its replay is generated normally and independently re-simulated by
the existing verifier; no ticks, inputs or claims are padded to force a result.
68 changes: 68 additions & 0 deletions phaser-asteroids/docs/gameplay-experiment-b.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Experiment B: volatile explosions (local only)

Experiment A remains in place. Both experiments belong to the unpublished rules `1.1.0`; replay schema remains `1`.
No Worker deployment, production leaderboard changes, commits or pushes were performed.

## Gameplay

- `VOLATILE_EXPLOSION_RADIUS` in `src/core/constants.ts` starts at **110 world pixels**. The target's collision
radius counts: a radius-20 rock touching a blast at a centre distance of 130 is hit.
- Every volatile destruction detonates once, including shots, lasers, boost rams, UFO shots and body collisions.
Only living, non-dying asteroids are eligible. Ships, UFOs, shots and pickups take no blast damage.
- Each blast visits a snapshot of the asteroid list once. Destruction marks a rock dying before it can be
targeted again. Newly destroyed volatile rocks append a blast to an explicit breadth-first queue, processed
synchronously in stable asteroid-list order. There is no recursive chain traversal or lingering damage zone.
- Standard rocks die; armor takes one ordinary hit per blast. Two overlapping blasts can finish armored rocks.
- Player credit follows the entire chain. Kills use the existing combo, points and multiplier calculation,
and the existing power-up drop rules. No explosion bonus multiplier was added.
- UFO-initiated chains pay nobody, retaining the existing uncredited-hit combo/drop rules. A body collision
still pays nothing and gives no combo/drop for the original rock; subsequent blast kills remain uncredited
and use the ordinary hit rules. Competing shots cannot steal a rock already marked dying.
- Splitting is unchanged, including volatile children. Children appear after the normal death delay and are
outside the completed chain's target snapshot. A later, separate blast can hit them normally.
- Volatile unlock (60 seconds), spawn weight (0.12), orange color, bonus points, all Experiment A balancing,
power-up behavior, enemy AI, player abilities and difficulty progression are preserved.

## Feedback and limits

Each detonation has its own orange/yellow expanding double ring and 12 short spark strokes, fading over
0.32 seconds. Chain links stagger their visuals by 25 ms per depth (maximum 100 ms), with immediate gameplay
damage. At most 32 blast visuals remain active. There is no fullscreen flash, texture or particle emitter.
These new visuals use no random numbers and can be discarded without changing gameplay/RNG state.

Volatile breakups replace the ordinary sound with the existing large explosion sample at a deeper playback
rate (0.8, increasing by 0.06 per chain depth up to 1.04). Existing explosion voice caps and overlap falloff
remain active. Shake requests are 6 pixels, using the existing 100 ms cooldown and global 12-pixel cap;
simultaneous chain links do not stack shake.

## Focused validation

`tests/volatileExplosion.test.ts` covers range boundaries, standard and armored damage, cyclic and dense
chains, player-2 score/combo ownership, uncredited causes, duplicate prevention, player/UFO immunity,
splitting, effect/audio caps, matching seeded outcomes with presentation discarded, and a short genuine
recording accepted by the local ranked verifier. Existing asteroid and audio tests are also relevant.

Validation passed: all 121 tests in the selected explosion/asteroid/audio files, nine targeted ranked
integration cases, and both client and server TypeScript checks. No browser suite or production build was run.

The existing genuine ranked reference replay is accepted by the authoritative local verifier with a score
of **13959** (A alone: 7884). Its longer survival also requires fixture clocks to advance by actual replay
duration instead of a fixed 200 seconds. This is a deterministic fixture result, not a balance estimate.
Both browser and server import the same updated simulation. Rules stay `1.1.0`; A-only development replays
with that version are no longer outcome-compatible. The coordinated-release considerations in
`gameplay-experiment-a.md` still apply. Production was not contacted.

## Trying it

From `phaser-asteroids`, run:

```powershell
npm run dev -- --host 127.0.0.1 --port 5173
```

Open `http://127.0.0.1:5173/`, then **PLAY** / Space on desktop or **PRACTICE** on mobile.
Volatile spawns become eligible at 60 seconds; the unlock does not guarantee an immediate spawn.
Shoot orange rocks near groups, try overlapping blasts on armor, and try laser/boost-triggered chains.

Watch score/combo growth and drop density in clusters, the continuing threat from volatile children,
and whether the boom/rings remain readable and comfortable during larger chains on mobile.
4 changes: 2 additions & 2 deletions phaser-asteroids/scripts/ranked-ui.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ try {
.map((r, i) => {
const id = `00000000-0000-4000-8000-${String(i + 1).padStart(12, '0')}`;
const run = `00000000-0000-4000-9000-${String(i + 1).padStart(12, '0')}`;
return `INSERT INTO runs (id, token_hash, seed, rules_version, config_json, created_at, expires_at, status, finished_at, score_id) VALUES ('${run}', 'x', 1, '1.0.0', '{}', ${r.at - 60000}, ${r.at + 3600000}, 'accepted', ${r.at}, '${id}');
INSERT INTO scores (id, run_id, score, nickname, completed_at, rules_version, ticks, duration_ms) VALUES ('${id}', '${run}', ${r.score}, '${r.nick}', ${r.at}, '1.0.0', 3600, 60000);`;
return `INSERT INTO runs (id, token_hash, seed, rules_version, config_json, created_at, expires_at, status, finished_at, score_id) VALUES ('${run}', 'x', 1, '1.1.0', '{}', ${r.at - 60000}, ${r.at + 3600000}, 'accepted', ${r.at}, '${id}');
INSERT INTO scores (id, run_id, score, nickname, completed_at, rules_version, ticks, duration_ms) VALUES ('${id}', '${run}', ${r.score}, '${r.nick}', ${r.at}, '1.1.0', 3600, 60000);`;
})
.join('\n');
check('seeded 24 verified scores (20 this week, 4 from last week) straight into D1', B.exec(sql));
Expand Down
4 changes: 2 additions & 2 deletions phaser-asteroids/server/scripts/worker-e2e.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,10 @@ try {

// --- challenge issuance -------------------------------------------------------------------------------------------------
const health = await api('GET', '/api/v1/health');
check('health reports rules version', health.json?.rulesVersion === '1.0.0');
check('health reports rules version', health.json?.rulesVersion === '1.1.0');
const probe = await api('POST', '/api/v1/runs', { body: JSON.stringify({ seed: 1, config: { playerCount: 2 } }), headers: { 'content-type': 'application/json' } });
check('POST /runs issues a challenge (201) with server-chosen seed and approved config', probe.status === 201 && probe.json.seed !== 1 && probe.json.config.playerCount === 1);
check('challenge carries id, secret token, rules version, expiry', !!probe.json.runId && probe.json.token?.length >= 40 && probe.json.rulesVersion === '1.0.0' && Date.parse(probe.json.expiresAt) > Date.now());
check('challenge carries id, secret token, rules version, expiry', !!probe.json.runId && probe.json.token?.length >= 40 && probe.json.rulesVersion === '1.1.0' && Date.parse(probe.json.expiresAt) > Date.now());

// --- prepare several real games, all played against server-issued seeds -----------------------------------------------------
const honest = await playableRun();
Expand Down
6 changes: 3 additions & 3 deletions phaser-asteroids/server/tests/harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function botRun(seed: number, opts: Omit<BotOptions, 'seed'> = {}): BotRu
return structuredClone(run);
}

/** 2-minute game, score 9114 (the Phase 1 reference run). */
/** Genuine reference game; combined experiments A+B under rules 1.1.0 produce 13959 points for this seed. */
export const REFERENCE_SEED = 54321;

export interface Harness {
Expand Down Expand Up @@ -148,12 +148,12 @@ export async function insertScore(
{
sql: `INSERT INTO runs (id, token_hash, seed, rules_version, config_json, created_at, expires_at, status, finished_at, score_id)
VALUES (?, 'x', 1, ?, '{}', ?, ?, 'accepted', ?, ?)`,
params: [runId, s.rules ?? '1.0.0', s.completedAt - 60_000, s.completedAt + 3_600_000, s.completedAt, id],
params: [runId, s.rules ?? '1.1.0', s.completedAt - 60_000, s.completedAt + 3_600_000, s.completedAt, id],
},
{
sql: `INSERT INTO scores (id, run_id, score, nickname, completed_at, rules_version, ticks, duration_ms, visibility)
VALUES (?, ?, ?, ?, ?, ?, 3600, 60000, ?)`,
params: [id, runId, s.score, s.nickname ?? 'Tester', s.completedAt, s.rules ?? '1.0.0', s.visibility ?? 'visible'],
params: [id, runId, s.score, s.nickname ?? 'Tester', s.completedAt, s.rules ?? '1.1.0', s.visibility ?? 'visible'],
},
]);
return id;
Expand Down
4 changes: 2 additions & 2 deletions phaser-asteroids/server/tests/leaderboard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ describe('weekly leaderboard', () => {
expect(res.body.ranks).toEqual({ allTime: 2, weekly: 1 });
const detail = await h.call('GET', `/api/v1/scores/${res.body.score.id}`);
expect(detail.body.ranks).toEqual({ allTime: 2, weekly: 1 });
expect(detail.body.score.score).toBe(9114);
expect(detail.body.score.score).toBe(13959);
});
});

Expand Down Expand Up @@ -198,7 +198,7 @@ describe('routing hygiene', () => {
it('health reports the supported rules version', async () => {
const h = makeHarness();
const res = await h.call('GET', '/api/v1/health');
expect(res.body).toMatchObject({ ok: true, rulesVersion: '1.0.0', schemaVersion: 1 });
expect(res.body).toMatchObject({ ok: true, rulesVersion: '1.1.0', schemaVersion: 1 });
});
it('wrong methods and unknown paths get JSON errors', async () => {
const h = makeHarness();
Expand Down
Loading
Loading