Versus mode: attack vs defend (sim, bots, server, client)

One player defends, the other plays the Internet: earns credits over time and
spends them on packets, upgrades and sabotage. Two rounds with swapped roles,
timed (the faster fall wins). Built end to end, NOT yet QA'd or balanced.

Sim (public/js/sim.js, TD.VS table): attacker economy (income, lifetime bonus,
leak payback), spawn / stage / launch convoys, 7 tech tracks, abilities (EMP,
decoy, surge, DDoS), defender tools (scan, patch, repair, quarantine), role-checked
commands, round result, role-private state. Co-op/solo unchanged (24 scripted
games replay identically).

Bots (public/js/bot.js, tools/versus.js): defender (maze + turrets) and attacker
(budgeted spender reading the tower mix); headless bot-vs-bot runner.

Server (server/versus.js, protocol doc): versus rooms with lobby / countdown /
playing / roundover / matchover, role stamping, cross-role refusal, role-private
priv messages at 4 Hz, computer seat, freeze/forfeit rules, no pause/speed.

Client (public/js/versus.js): setup dialog (role, length, vs computer or online),
countdown, defender tools row, attacker unit shop with convoy + launch, tech and
abilities, gateway choice, round/match screens, sounds, phone-first dock rows.

Status and next steps (balance: the attacker currently wins ~100% of bot rounds;
QA with two browsers; layout matrix rerun) are in docs/NEXT.md and docs/VERSUS.md.
The full planned workflow incl. balance/QA prompts is in docs/workflows/versus-full.js.

253 unit tests pass; one smoke e2e run; no other e2e per the user's request.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tb8pW2KAN4oFkh1aK1BfD8
This commit is contained in:
Claude 2026-10-11 10:22:29 +00:00
parent b4ae6cb57d
commit 2098d59c1f
23 changed files with 6166 additions and 90 deletions

View file

@ -104,6 +104,15 @@ not `join` within 10 s is closed. When all 50 rooms exist, a room in which nobod
its `GRACE_MS`) is deleted to make room for a new one, longest-abandoned first, so on a full server the grace period is
not guaranteed; rooms with somebody online are never evicted (the newcomer gets `too_many_rooms`).
**Versus rooms** (attack vs defend, `docs/PROTOCOL.md` "Versus") count against the same 50 rooms and need nothing extra: no new port, no new environment variable,
the same WebSocket. Two things differ from co-op that an operator may notice. A disconnected player freezes the round for everybody until they are back or `GRACE_MS`
has passed (then the other player wins the match), so a long `GRACE_MS` means a long wait for the player who stayed. And a room may hold a computer opponent that runs
inside the server process: it thinks about 4 times per game second and costs well under 1 ms of CPU per game second on average. A single decision of a computer defender
(its opening purchases) takes 10-20 ms, up to ~80 ms on a cold process. A decision cannot be interrupted, so the server gates *when* the computers may start thinking:
only while less than 15 ms were spent on them in this 8 ms loop iteration, and a decision that took `d` buys its room a quiet period of `3d`. Many computer rooms starting at
the same moment are therefore spread over a few hundred milliseconds instead of stalling the other rooms.
The log has one line per versus round (start, result, forfeit).
What the server does, relevant to a proxy setup:
* **Real client IP** is used only for the log and the per-IP cap. With `TRUST_PROXY=auto` and a private/loopback peer