From f0712d3854d85e03aed303e96dafc1248500f5ca Mon Sep 17 00:00:00 2001 From: Krzysztof kuhy Rudnicki Date: Sun, 9 Aug 2026 23:06:20 +0200 Subject: [PATCH] reverse_survivors: add splitter, artillery, warden and the leech boss MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Splitter dies into three rushers, so killing it creates pressure rather than relieving it. Artillery outranges the survivor (460 vs its 260) and holds station beyond reach, the first unit its kiting AI cannot answer. Warden outruns it. Leech is a third boss. Two new EnemySpec fields carry this: spawnKind generalizes the hivemind's hardcoded 'rusher' minion, and splitCount drives on-death splitting. split() is called unconditionally and is a no-op at splitCount 0 — a guard branch would need two tests to satisfy the 100% gate and buys nothing. Child offsets are fixed rather than drawn from the RNG, so seeded replays are unchanged. 105 tests, 100% coverage. Branch count stays at 117: this adds none. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_01VFyXexNjMQG9V7K8de17fc --- ...rvivors-gameplay-extension-2026-08-09.json | 18 +++ ...erse-survivors-new-enemies-2026-08-09.json | 33 +++++ reverse_survivors/src/core/sim.test.ts | 119 +++++++++++++++++- reverse_survivors/src/core/sim.ts | 24 +++- reverse_survivors/src/core/types.ts | 57 ++++++++- reverse_survivors/src/render/draw.ts | 8 ++ 6 files changed, 249 insertions(+), 10 deletions(-) create mode 100644 docs/superpowers/contracts/reverse-survivors-gameplay-extension-2026-08-09.json create mode 100644 docs/superpowers/evidence/reverse-survivors-new-enemies-2026-08-09.json diff --git a/docs/superpowers/contracts/reverse-survivors-gameplay-extension-2026-08-09.json b/docs/superpowers/contracts/reverse-survivors-gameplay-extension-2026-08-09.json new file mode 100644 index 00000000..b0191fde --- /dev/null +++ b/docs/superpowers/contracts/reverse-survivors-gameplay-extension-2026-08-09.json @@ -0,0 +1,18 @@ +{ + "title": "Reverse Survivors gameplay extension: enemies, statuses, director powers, difficulty", + "objective": "Extend the game with four systems, landed as four independently-green commits: new enemy kinds; survivor status debuffs (slow/suppress/bleed); director powers that buy back placement control (ambush/frenzy/rift); and difficulty tiers. Each commit must typecheck, lint at --max-warnings 0, and hold 100% coverage on its own, so the history stays bisectable.", + "acceptance_criteria": [ + "Every commit passes `npm run check` in reverse_survivors/ standalone: tsc --noEmit clean, eslint --max-warnings 0 clean, vitest at 100% statements/branches/functions/lines.", + "No lint suppressions, @ts-ignore, or coverage excludes are introduced.", + "New status logic contributes zero branches, verified against the v8 branch count.", + "Seeded replays stay deterministic: the same seed and action sequence produce identical outcomes.", + "The game runs and both sides can still win, verified by driving the real simulation rather than tests alone." + ], + "out_of_scope": [ + "Endless mode: fmtTime(Infinity) renders Infinity:NaN and would need a guard plus tests for a mode whose only content is the same game but longer.", + "localStorage difficulty persistence: its catch arm is only reachable by stubbing a throwing setItem, which tests the mock rather than the game.", + "The pending dependency refresh (7 packages one patch behind) ships separately.", + "Rebalancing the pre-existing economy, where a trickle strategy loses to the survivor's kill rate." + ], + "verifier": "npm run check (typecheck + eslint --max-warnings 0 + vitest --coverage at 100%), npm run build, and a headless full-game playtest driving src/core/sim.ts via vite-node" +} diff --git a/docs/superpowers/evidence/reverse-survivors-new-enemies-2026-08-09.json b/docs/superpowers/evidence/reverse-survivors-new-enemies-2026-08-09.json new file mode 100644 index 00000000..7b55a134 --- /dev/null +++ b/docs/superpowers/evidence/reverse-survivors-new-enemies-2026-08-09.json @@ -0,0 +1,33 @@ +{ + "intent": "Add four enemy kinds to Reverse Survivors: Splitter, Artillery, Warden, and the Leech boss.", + "scope": [ + "reverse_survivors/src/core/types.ts (specs, UnitKind/BossKind, orders, unlock/cooldown tables)", + "reverse_survivors/src/core/sim.ts (split(), spawnKind generalization)", + "reverse_survivors/src/render/draw.ts (colors, boss ring flags)", + "Non-goal: status debuffs, director powers and difficulty tiers ship as their own commits" + ], + "changes": [ + "Two new EnemySpec fields: spawnKind and splitCount. spawnKind generalizes the previously hardcoded 'rusher' in the hivemind's minion spawn; splitCount drives on-death splitting.", + "Splitter (34) dies into 3 rushers at fixed 120-degree offsets, so killing it creates pressure. Children are rushers, making recursion structurally impossible - no depth counter needed.", + "Artillery (52) has 460 range against the survivor's 260 and keepDistance 420, so it outranges the survivor's kiting AI entirely.", + "Warden (40) moves at 215, faster than the survivor's base 150.", + "Leech (190, unlocks at 180s) is a third boss, cheaper and squishier than the Colossus.", + "split() is called unconditionally from killByShot; splitCount: 0 makes it a no-op, which avoids a guard branch that would need two tests under the 100% gate.", + "Child positions use fixed angular offsets rather than the RNG, so seeded replays are unaffected." + ], + "verification": [ + { + "command": "npm run check (typecheck + eslint --max-warnings 0 + vitest --coverage)", + "result": "pass", + "evidence": "105 tests passed. Coverage 100% on all four metrics: statements 417/417, branches 117/117, functions 76/76, lines 402/402. Branch count unchanged from the 117 baseline, confirming this feature adds zero branches." + } + ], + "risks": [ + "Balance is simulation-verified rather than human-playtested; the new units may need retuning.", + "Splitter children spawn into state.enemies during projectilesStep, so a later projectile in the same tick can interact with them. Verified: SPLIT_RADIUS 22 exceeds rusher radius 9 + projectile radius 4, so children spawn outside immediate hit range." + ], + "rollback": [ + "git revert the commit; no data migration and no persisted state is involved.", + "After rollback run `npm run check` in reverse_survivors/ and confirm 95 tests pass at 100% coverage." + ] +} diff --git a/reverse_survivors/src/core/sim.test.ts b/reverse_survivors/src/core/sim.test.ts index 627ea67e..68f539fb 100644 --- a/reverse_survivors/src/core/sim.test.ts +++ b/reverse_survivors/src/core/sim.test.ts @@ -1,6 +1,7 @@ import { describe, expect, it } from 'vitest' import { - applyUpgrade, createInitialState, DANGER_RADIUS, grantXp, makeEnemy, step, xpForLevel, + applyUpgrade, createInitialState, DANGER_RADIUS, grantXp, makeEnemy, SPLIT_RADIUS, step, + xpForLevel, } from './sim' import type { GameState, Projectile } from './types' import { ARENA, GAME_DURATION } from './types' @@ -368,3 +369,119 @@ describe('game end', () => { expect(s.director.energy).toBeLessThan(30) }) }) + +describe('splitter', () => { + it('dies into three rushers at fixed offsets', () => { + const s = fresh() + const sp = makeEnemy(s, 'splitter', { x: 300, y: 300 }) + shot(s, 300, 300, 999) + step(s, [], 0.001) + const children = s.enemies.filter((e) => e.id !== sp.id) + expect(children).toHaveLength(3) + expect(children.every((c) => c.kind === 'rusher')).toBe(true) + // Children drift toward the survivor within the same tick, so assert the + // spawn ring loosely — the exact geometry is pinned by the test below. + for (const c of children) { + expect(Math.hypot(c.pos.x - 300, c.pos.y - 300)).toBeLessThan(SPLIT_RADIUS + 5) + } + }) + + it('spawns children on a ring at 120-degree offsets', () => { + const s = fresh() + makeEnemy(s, 'splitter', { x: 300, y: 300 }) + shot(s, 300, 300, 999) + // dt of 0 isolates the spawn geometry from the movement that follows it. + step(s, [], 0) + const angles = s.enemies + .map((e) => Math.atan2(e.pos.y - 300, e.pos.x - 300)) + .sort((a, b) => a - b) + expect(angles).toHaveLength(3) + // Pairwise gaps without indexing (noUncheckedIndexedAccess would widen those). + const gaps: number[] = [] + let prev: number | null = null + for (const a of angles) { + if (prev !== null) { + gaps.push(a - prev) + } + prev = a + } + expect(gaps).toHaveLength(2) + for (const g of gaps) { + expect(g).toBeCloseTo((Math.PI * 2) / 3, 5) + } + }) + + it('children are deterministic and draw no RNG', () => { + const run = (): { x: number; y: number }[] => { + const s = fresh(42) + makeEnemy(s, 'splitter', { x: 300, y: 300 }) + shot(s, 300, 300, 999) + step(s, [], 0.001) + return s.enemies.map((e) => ({ x: e.pos.x, y: e.pos.y })) + } + expect(run()).toEqual(run()) + }) + + it('clamps children into the arena when it dies in a corner', () => { + const s = fresh() + makeEnemy(s, 'splitter', { x: 2, y: 2 }) + shot(s, 2, 2, 999) + step(s, [], 0.001) + for (const e of s.enemies) { + expect(e.pos.x).toBeGreaterThanOrEqual(10) + expect(e.pos.y).toBeGreaterThanOrEqual(10) + } + }) + + it('a later projectile in the same tick can hit a fresh child', () => { + const s = fresh() + makeEnemy(s, 'splitter', { x: 300, y: 300 }) + shot(s, 300, 300, 999) + shot(s, 300 + SPLIT_RADIUS, 300, 999) + step(s, [], 0.001) + expect(s.survivor.kills).toBe(2) + }) + + it('non-splitting kinds spawn no children', () => { + const s = fresh() + makeEnemy(s, 'rusher', { x: 300, y: 300 }) + shot(s, 300, 300, 999) + step(s, [], 0.001) + expect(s.enemies).toHaveLength(0) + }) +}) + +describe('new units', () => { + it('artillery outranges the survivor and fires while it cannot', () => { + const s = fresh() + const a = makeEnemy(s, 'artillery', { x: CENTER.x + 400, y: CENTER.y }) + a.fireTimer = 0 + step(s, [], 0.001) + expect(s.projectiles.some((p) => p.from === 'enemy')).toBe(true) + expect(s.projectiles.some((p) => p.from === 'survivor')).toBe(false) + }) + + it('artillery holds station at its keep distance', () => { + const s = fresh() + const a = makeEnemy(s, 'artillery', { x: CENTER.x + 420, y: CENTER.y }) + const before = a.pos.x + step(s, [], 0.016) + expect(a.pos.x).toBeCloseTo(before, 5) + }) + + it('warden closes faster than a rusher', () => { + const s = fresh() + const w = makeEnemy(s, 'warden', { x: CENTER.x + 300, y: CENTER.y }) + const r = makeEnemy(s, 'rusher', { x: CENTER.x + 300, y: CENTER.y }) + step(s, [], 0.016) + expect(CENTER.x + 300 - w.pos.x).toBeGreaterThan(CENTER.x + 300 - r.pos.x) + }) + + it('the hivemind still births rushers via spawnKind', () => { + const s = fresh() + const h = makeEnemy(s, 'hivemind', { x: 40, y: 40 }) + h.spawnTimer = 0 + step(s, [], 0.001) + expect(s.enemies.some((e) => e.kind === 'rusher')).toBe(true) + }) +}) diff --git a/reverse_survivors/src/core/sim.ts b/reverse_survivors/src/core/sim.ts index 8fb715cf..4fd8365f 100644 --- a/reverse_survivors/src/core/sim.ts +++ b/reverse_survivors/src/core/sim.ts @@ -1,7 +1,7 @@ import { applyAction, tickDirector } from './director' import { createRng, pick } from './rng' import type { - DirectorAction, Enemy, EnemyKind, GameState, Survivor, UpgradeId, + DirectorAction, Enemy, EnemyKind, EnemySpec, GameState, Survivor, UpgradeId, } from './types' import { ARENA, CONTACT_COOLDOWN, ENERGY_START, ENEMY_SPECS, GAME_DURATION, UPGRADE_POOL, @@ -46,7 +46,7 @@ export const createInitialState = (seed: number, duration = GAME_DURATION): Game director: { energy: ENERGY_START, waveIndex: 0, - bossCooldowns: { colossus: 0, hivemind: 0 }, + bossCooldowns: { colossus: 0, hivemind: 0, leech: 0 }, }, upgrades: [], nextId: 1, @@ -162,6 +162,23 @@ const detonate = (state: GameState, enemy: Enemy): void => { } } +export const SPLIT_RADIUS = 22 + +/** + * Emits `splitCount` children at fixed angular offsets. Deterministic on purpose: + * drawing from the RNG here would shift every seeded replay downstream. + * Loop-only — `splitCount: 0` makes this a no-op without a guard branch. + */ +const split = (state: GameState, spec: EnemySpec, pos: Vec): void => { + for (let i = 0; i < spec.splitCount; i += 1) { + const angle = (Math.PI * 2 * i) / spec.splitCount + makeEnemy(state, spec.spawnKind, { + x: clamp(pos.x + Math.cos(angle) * SPLIT_RADIUS, 10, ARENA.w - 10), + y: clamp(pos.y + Math.sin(angle) * SPLIT_RADIUS, 10, ARENA.h - 10), + }) + } +} + const killByShot = (state: GameState, enemy: Enemy): void => { const spec = ENEMY_SPECS[enemy.kind] state.survivor.kills += 1 @@ -169,6 +186,7 @@ const killByShot = (state: GameState, enemy: Enemy): void => { if (spec.detonates) { detonate(state, enemy) } + split(state, spec, enemy.pos) } const MOVE_FNS: Record<'chase' | 'skirmish', (e: Enemy, sv: Survivor, d: number) => Vec> = { @@ -226,7 +244,7 @@ const enemiesStep = (state: GameState, dt: number): void => { if (spec.spawnEvery > 0) { e.spawnTimer = Math.max(0, e.spawnTimer - dt) if (e.spawnTimer === 0) { - spawned.push({ kind: 'rusher', pos: { x: e.pos.x, y: e.pos.y } }) + spawned.push({ kind: spec.spawnKind, pos: { x: e.pos.x, y: e.pos.y } }) e.spawnTimer = spec.spawnEvery } } diff --git a/reverse_survivors/src/core/types.ts b/reverse_survivors/src/core/types.ts index f458a73d..884eb595 100644 --- a/reverse_survivors/src/core/types.ts +++ b/reverse_survivors/src/core/types.ts @@ -7,8 +7,9 @@ export const CONTACT_COOLDOWN = 0.5 export const ENERGY_CAP = 400 export const ENERGY_START = 30 -export type UnitKind = 'rusher' | 'stalker' | 'tank' | 'bomber' -export type BossKind = 'colossus' | 'hivemind' +export type UnitKind = + | 'rusher' | 'stalker' | 'tank' | 'bomber' | 'splitter' | 'artillery' | 'warden' +export type BossKind = 'colossus' | 'hivemind' | 'leech' export type EnemyKind = UnitKind | BossKind export type MoveMode = 'chase' | 'skirmish' @@ -33,6 +34,10 @@ export interface EnemySpec { readonly blastDamage: number /** 0 disables minion spawning. */ readonly spawnEvery: number + /** What `spawnEvery` and `splitCount` emit. Always a kind — the `> 0` gates guard every read. */ + readonly spawnKind: UnitKind + /** 0 disables on-death splitting. */ + readonly splitCount: number } const spec = (s: EnemySpec): EnemySpec => s @@ -43,43 +48,83 @@ export const ENEMY_SPECS: Record = { contactDamage: 6, xp: 4, move: 'chase', projDamage: 0, projSpeed: 0, fireRange: 0, fireCooldown: 0, keepDistance: 0, detonates: false, blastRadius: 0, blastDamage: 0, spawnEvery: 0, + spawnKind: 'rusher', splitCount: 0, }), stalker: spec({ name: 'Stalker', cost: 24, hp: 20, speed: 110, radius: 10, contactDamage: 4, xp: 8, move: 'skirmish', projDamage: 7, projSpeed: 260, fireRange: 250, fireCooldown: 1.6, keepDistance: 200, detonates: false, blastRadius: 0, blastDamage: 0, spawnEvery: 0, + spawnKind: 'rusher', splitCount: 0, }), tank: spec({ name: 'Tank', cost: 45, hp: 120, speed: 55, radius: 18, contactDamage: 14, xp: 20, move: 'chase', projDamage: 0, projSpeed: 0, fireRange: 0, fireCooldown: 0, keepDistance: 0, detonates: false, blastRadius: 0, blastDamage: 0, spawnEvery: 0, + spawnKind: 'rusher', splitCount: 0, }), bomber: spec({ name: 'Bomber', cost: 30, hp: 16, speed: 140, radius: 10, contactDamage: 0, xp: 10, move: 'chase', projDamage: 0, projSpeed: 0, fireRange: 0, fireCooldown: 0, keepDistance: 0, detonates: true, blastRadius: 70, blastDamage: 22, spawnEvery: 0, + spawnKind: 'rusher', splitCount: 0, + }), + splitter: spec({ + name: 'Splitter', cost: 34, hp: 30, speed: 95, radius: 13, + contactDamage: 5, xp: 12, move: 'chase', + projDamage: 0, projSpeed: 0, fireRange: 0, fireCooldown: 0, keepDistance: 0, + detonates: false, blastRadius: 0, blastDamage: 0, spawnEvery: 0, + spawnKind: 'rusher', splitCount: 3, + }), + artillery: spec({ + name: 'Artillery', cost: 52, hp: 26, speed: 70, radius: 12, + contactDamage: 0, xp: 16, move: 'skirmish', + projDamage: 13, projSpeed: 190, fireRange: 460, fireCooldown: 2.6, keepDistance: 420, + detonates: false, blastRadius: 0, blastDamage: 0, spawnEvery: 0, + spawnKind: 'rusher', splitCount: 0, + }), + warden: spec({ + name: 'Warden', cost: 40, hp: 34, speed: 215, radius: 8, + contactDamage: 7, xp: 14, move: 'chase', + projDamage: 0, projSpeed: 0, fireRange: 0, fireCooldown: 0, keepDistance: 0, + detonates: false, blastRadius: 0, blastDamage: 0, spawnEvery: 0, + spawnKind: 'rusher', splitCount: 0, }), colossus: spec({ name: 'Colossus', cost: 150, hp: 700, speed: 40, radius: 34, contactDamage: 30, xp: 80, move: 'chase', projDamage: 0, projSpeed: 0, fireRange: 0, fireCooldown: 0, keepDistance: 0, detonates: false, blastRadius: 0, blastDamage: 0, spawnEvery: 0, + spawnKind: 'rusher', splitCount: 0, }), hivemind: spec({ name: 'Hivemind', cost: 220, hp: 420, speed: 60, radius: 28, contactDamage: 10, xp: 100, move: 'chase', projDamage: 0, projSpeed: 0, fireRange: 0, fireCooldown: 0, keepDistance: 0, detonates: false, blastRadius: 0, blastDamage: 0, spawnEvery: 2.5, + spawnKind: 'rusher', splitCount: 0, + }), + leech: spec({ + name: 'Leech', cost: 190, hp: 500, speed: 75, radius: 30, + contactDamage: 12, xp: 90, move: 'chase', + projDamage: 0, projSpeed: 0, fireRange: 0, fireCooldown: 0, keepDistance: 0, + detonates: false, blastRadius: 0, blastDamage: 0, spawnEvery: 0, + spawnKind: 'rusher', splitCount: 0, }), } as const -export const UNIT_ORDER: readonly [UnitKind, ...UnitKind[]] = ['rusher', 'stalker', 'tank', 'bomber'] -export const BOSS_ORDER: readonly [BossKind, ...BossKind[]] = ['colossus', 'hivemind'] -export const BOSS_UNLOCK_AT: Record = { colossus: 60, hivemind: 120 } -export const BOSS_COOLDOWN: Record = { colossus: 25, hivemind: 30 } +export const UNIT_ORDER: readonly [UnitKind, ...UnitKind[]] = [ + 'rusher', 'stalker', 'tank', 'bomber', 'splitter', 'artillery', 'warden', +] +export const BOSS_ORDER: readonly [BossKind, ...BossKind[]] = ['colossus', 'hivemind', 'leech'] +export const BOSS_UNLOCK_AT: Record = { + colossus: 60, hivemind: 120, leech: 180, +} +export const BOSS_COOLDOWN: Record = { + colossus: 25, hivemind: 30, leech: 28, +} export type UpgradeId = 'damage' | 'fireRate' | 'speed' | 'vitality' | 'regen' | 'multishot' export const UPGRADE_POOL: readonly [UpgradeId, ...UpgradeId[]] = [ diff --git a/reverse_survivors/src/render/draw.ts b/reverse_survivors/src/render/draw.ts index d26ed009..f061e344 100644 --- a/reverse_survivors/src/render/draw.ts +++ b/reverse_survivors/src/render/draw.ts @@ -30,8 +30,12 @@ const ENEMY_COLORS: Record = { stalker: '#b06ce8', tank: '#8a4b3c', bomber: '#e0a13d', + splitter: '#5fae6b', + artillery: '#d4693a', + warden: '#e6d15c', colossus: '#7d2c50', hivemind: '#5a3d8a', + leech: '#3f7d6e', } const IS_BOSS: Record = { @@ -39,8 +43,12 @@ const IS_BOSS: Record = { stalker: false, tank: false, bomber: false, + splitter: false, + artillery: false, + warden: false, colossus: true, hivemind: true, + leech: true, } const circle = (ctx: Ctx2D, x: number, y: number, r: number): void => {