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:
parent
b4ae6cb57d
commit
2098d59c1f
23 changed files with 6166 additions and 90 deletions
|
|
@ -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
|
||||
|
|
|
|||
20
docs/NEXT.md
20
docs/NEXT.md
|
|
@ -33,7 +33,7 @@ and a check that the layout holds on **tablets and foldables**.
|
|||
| 2 | Co-op robustness (stalled-render tower loss, half-open sockets, idempotent upgrade/wave, restart message), audio + keyboard + a11y | **done 2026-10-10** (QA passed) |
|
||||
| 3 | New enemies (Daemon healer, Proxy shielded, Botnet swarm) and towers (Sandbox stun, Load Balancer buff), glyphs/shapes, gallery e2e; Orbital Uplink (4 levels, priced 1500 + 25% per owned, upgrades scale equally; ); 4 new maps | **done 2026-10-10** (QA passed) |
|
||||
| 4 | Difficulty picker (Easy/Normal/Hard) + ONE time-boxed balance pass (IDS no longer sufficient, credit snowball tamed, Mortar/Arc/Filter buffed, flyers slower); Uplink price step set to 30% per owned | **done 2026-10-11** (QA passed) |
|
||||
| 5 | Attack-vs-defend versus mode, bots for both sides | design in `docs/VERSUS.md`, workflow drafted |
|
||||
| 5 | Attack-vs-defend versus mode, bots for both sides | **built 2026-10-11, NOT QA'd, NOT balanced** (sim, bots, server, client; see below) |
|
||||
| 6 | Server leaderboard (needs `StateDirectory=netwall` + `DATA_DIR`; solo scores are client-reported) and an opt-in public room list | after 5 |
|
||||
| any | Fold/tablet real-device check; open items below | |
|
||||
|
||||
|
|
@ -48,6 +48,24 @@ and a check that the layout holds on **tablets and foldables**.
|
|||
* If room codes ever get longer than 4 characters, boot's regex and the `inCode` maxlength must change together.
|
||||
|
||||
|
||||
### Versus mode: where it stands and what is left
|
||||
|
||||
Built: sim rules + economy + tech + abilities + defender tools (`TD.VS` table), `public/js/bot.js` (defender and attacker bots), `tools/versus.js`
|
||||
(bot-vs-bot runner), server rooms/phases/roles/forfeit/private data/computer seat (`server/versus.js`), protocol (`docs/PROTOCOL.md` "Versus"),
|
||||
client (`public/js/versus.js`: setup dialog, countdown, role-aware HUD, shop, convoy/launch, tech, abilities, tools, round/match screens). 253 unit tests
|
||||
pass; the client was played by hand (local match vs the computer through both rounds, online rooms on the real server). **No e2e, no layout-matrix
|
||||
run, no independent QA, no balance pass** (the user asked to skip them for now).
|
||||
|
||||
Left to do, in order:
|
||||
1. **Balance** with `node tools/versus.js --maps all --limit 720 --seeds 6`: the attacker wins ~100% today. Cheapest lever: raise the buyCost of botnet
|
||||
and spam (3 credits each; botnet 8 / spam 6 flips it to ~0%); target 40-60% for equal bots on every map. The `buyCost` lives in `ENEMIES`, the rest in `TD.VS`.
|
||||
2. **QA** with two real browsers (prompt in `docs/workflows/versus-full.js`) plus the usual suites: `npm run e2e` (rerun the layout matrix: the menu foot now holds
|
||||
three buttons, the palette becomes the unit shop in versus, new dock rows in the side panel).
|
||||
3. Known limits from the client agent: a local computer match cannot be paused (opening the menu leaves the round running); no one-tap convoy presets (Rush, Swarm,
|
||||
Siege...); the defender sees no stealth/shield cue (by design); on very small phones the setup dialog's Online block needs a scroll; remote rematch, frozen/reconnect
|
||||
and reload-resume into a versus room were not exercised.
|
||||
4. Ideas not built: spectators, handicap sliders in the lobby, a leaderboard of attack times, an invite link that opens the versus lobby directly.
|
||||
|
||||
## Suggested order of work
|
||||
|
||||
1. **The wall bug above**, then the other confirmed high/medium client bugs:
|
||||
|
|
|
|||
136
docs/PROTOCOL.md
136
docs/PROTOCOL.md
|
|
@ -4,6 +4,8 @@ Two people play **the same map together**: one shared base, one shared credit po
|
|||
The Node server runs the game (the same `public/js/sim.js` the browser uses for solo play) and is the
|
||||
single source of truth. Clients send *commands*; the server steps the simulation and broadcasts *snapshots*.
|
||||
Clients never simulate in multiplayer; they render (with interpolation) what the server says.
|
||||
A room is either **co-op** (this document up to "Tick loop") or **versus** (attack vs defend, see "Versus" at the end: same transport, same
|
||||
snapshots, plus lobby / role-private messages); `join.mode` picks.
|
||||
|
||||
Transport: one WebSocket per player at `ws(s)://<host>/ws`, JSON text frames, one object per frame, field `t`
|
||||
= message type. Client -> server frames are capped at **2048 bytes** (`maxPayload`).
|
||||
|
|
@ -78,20 +80,25 @@ at a domain root and under a path prefix the proxy strips.
|
|||
Client's first message:
|
||||
|
||||
```
|
||||
{ t:'join', pid, name, room?, map?, difficulty? }
|
||||
{ t:'join', pid, name, room?, map?, difficulty?, mode?, limit?, rounds? }
|
||||
```
|
||||
* `pid` `^[A-Za-z0-9_-]{8,40}$` - random, generated by the client, kept in `sessionStorage` (stable across reloads).
|
||||
* `name` any string; server trims, strips control chars, caps at 16 chars, default `"Player"`.
|
||||
* `room` absent -> **create** a room. `map` must be a key of `TD.MAPS` (default `'open'`). `difficulty` must be a key of
|
||||
`TD.DIFFICULTIES` (`'easy'`, `'normal'`, `'hard'`; default `'normal'`, `null` counts as absent), see "Difficulty" below.
|
||||
Server generates a 4 character code from `ABCDEFGHJKLMNPQRSTUVWXYZ23456789`, unique among rooms.
|
||||
* `room` present (`^[A-Za-z0-9]{4}$`, case-insensitive -> upper-cased) -> **join**. `map` and `difficulty` are ignored on a join (not even
|
||||
validated): the joiner gets the room's, in `state.map` / `state.difficulty` of the `joined` message. A reconnect (same `pid`) is a join.
|
||||
* `mode`, `limit`, `rounds` (creating join only): `mode` is `'coop'` (the default; `null` counts as absent) or `'versus'` (see "Versus" below).
|
||||
For `'versus'`, `limit` is the round length in seconds, one of `TD.VS.LIMITS` (480, 720, 960; default 720) and `rounds` must be 2.
|
||||
They are checked after `map` and `difficulty`. A co-op creating join ignores `limit` and `rounds`.
|
||||
* `room` present (`^[A-Za-z0-9]{4}$`, case-insensitive -> upper-cased) -> **join**. `map`, `difficulty`, `mode`, `limit` and `rounds` are ignored on a join (not even
|
||||
validated): the joiner gets the room's, in `state.map` / `state.difficulty` (and `state.mode` / `state.limit` in versus) of the `joined` message. A reconnect (same `pid`) is a join.
|
||||
|
||||
Failure: `{ t:'error', code, msg }` then the server closes the socket (code 4000+).
|
||||
Codes: `bad_request`, `no_room`, `full` (two *other* pids already hold the slots), `too_many_rooms`, `bad_map`, `bad_difficulty`
|
||||
Codes: `bad_request`, `no_room`, `full` (two *other* pids already hold the slots, or a computer holds the second seat of a running versus match),
|
||||
`too_many_rooms`, `bad_map`, `bad_difficulty`
|
||||
(a creating join whose `difficulty` is not one of the table's keys: wrong type, `'toString'`, `'__proto__'`, ... all refused, no room is
|
||||
created, the socket closes with 4400; a bad `map` is checked first).
|
||||
created, the socket closes with 4400; a bad `map` is checked first), `bad_mode` (`mode` is neither `'coop'` nor `'versus'`), `bad_limit` (versus `limit` not in
|
||||
`TD.VS.LIMITS`, or not a number), `bad_rounds` (versus `rounds` is not 2). The three new codes also close with 4400 and create no room.
|
||||
|
||||
Success: reply to the joiner
|
||||
|
||||
|
|
@ -127,6 +134,7 @@ pid for the viewer's own entry and an opaque, stable per-room alias for the othe
|
|||
| `{t:'sync'}` | ask for a full state resend |
|
||||
| `{t:'newgame', map?, difficulty?}` | **host only**: replace the sim with a fresh `new Sim({map, difficulty})`; resets pause/speed. An absent (or `null`) `map` / `difficulty` keeps the room's current one, so a plain `{t:'newgame'}` is "play again" |
|
||||
| `{t:'leave'}` | leave now |
|
||||
| `{t:'vs', c, v?}` | **versus rooms only** (malformed in a co-op room): `role`, `ready`, `bot`, `start`, `next`, `rematch`; see "Versus" |
|
||||
|
||||
**Idempotent `upgrade` and `wave`.** Two players who press Upgrade (or Next wave) at the same moment both send the command; without
|
||||
a guard the tower would be upgraded twice and the second player charged for a level they never asked for, or two waves would start.
|
||||
|
|
@ -208,6 +216,7 @@ it when creating the room (`join.difficulty`) or when starting a new game (`newg
|
|||
|
||||
## Tick loop
|
||||
|
||||
(Co-op. A versus room has its own phases and only ticks while `playing` with every human online, at speed 1: see "Versus".)
|
||||
Fixed step `TD.STEP` (1/60 s) with an accumulator driven by `process.hrtime.bigint()`; real time elapsed is
|
||||
multiplied by `speed` (1-3) and ignored while `paused`; clamp elapsed per iteration to 250 ms so a stalled event
|
||||
loop does not fast-forward the game. Drive it with a `setInterval` of ~8 ms (or setTimeout chain) per room, or one
|
||||
|
|
@ -217,3 +226,120 @@ global loop for all rooms. Must keep working with several rooms at once.
|
|||
|
||||
`place`, `sell`, `up`, `shot`, `arc`, `boom`, `kill`, `leak`, `wave`, `clear`, `win`, `lose` (see `sim.js`).
|
||||
Treat them as opaque JSON.
|
||||
|
||||
## Versus (attack vs defend)
|
||||
|
||||
Design: `docs/VERSUS.md`. A versus room is created with `join.mode = 'versus'`. One player **defends** (builds the maze and turrets with the credits of
|
||||
`snap.g`), the other **attacks** (buys packets with credits only they can see); a match is two rounds with the roles swapped. The server is the
|
||||
only simulation (`new TD.Sim({ map, mode: 'versus', limit })`, a fresh one per round) and the only referee. Everything below is additive: a co-op room
|
||||
never sends or accepts any of it (a `vs` message or a versus command sent to a co-op room is malformed, exactly as before), the `joined` / `state`
|
||||
messages of a co-op room are byte-identical to what they were.
|
||||
|
||||
### Seats and roles
|
||||
* Two **seats** (the same slots 0 and 1). A seat is held by a human (as in co-op: grace period, reconnect by `pid`, host migration) or, in the
|
||||
lobby, by a **computer** (below). `roles` maps each seat to `'attacker'` or `'defender'` and is always one of each.
|
||||
* Round 1 roles: whatever the lobby says when the host starts (a coin flip until somebody chooses). Round 2 swaps them.
|
||||
* **The server decides the role of every command from the seat, for the current round**; a `role` or `by` field in a client message is ignored.
|
||||
A command for the other role is answered `{ t:'reject', c, reason:'role' }` and changes nothing.
|
||||
|
||||
### Phases
|
||||
```
|
||||
lobby --start--> countdown --> playing --> roundover --next--> countdown --> playing --> matchover --rematch--> countdown ...
|
||||
```
|
||||
| phase | what happens |
|
||||
|---|---|
|
||||
| `lobby` | roles, ready flags and the computer seat are agreed. The room's sim exists (so a joiner has a board) but **never ticks**; game commands are refused with `reason:'phase'`. Snapshots keep flowing (the client's watchdog needs them). |
|
||||
| `countdown` | a fresh sim for the round was built and sent as `{ t:'state', newgame:true, ... }`; `countdown` seconds left are in the `vs` message; nothing ticks, **no command is accepted** (`'phase'`). |
|
||||
| `playing` | the sim ticks (speed 1 only) while **every human seat is online**; commands are accepted. |
|
||||
| `roundover` | the round's `result` is shown; the next round starts when every human sent `next`, or after `vsNextMs` (30 s by default) whichever is first. |
|
||||
| `matchover` | after round 2 (or a forfeit): `scores` and `winner`. `rematch` starts a new match. |
|
||||
|
||||
Commands in `roundover` / `matchover` get `reason:'over'`; while a human seat is offline `reason:'frozen'`.
|
||||
|
||||
### Messages, client -> server
|
||||
Lobby and match control, all `{ t:'vs', c, ... }`. A malformed one (wrong type, unknown `c`) counts towards the 20-malformed limit; a well-formed one that is
|
||||
not allowed right now gets `{ t:'reject', c:<the vs command>, reason }`.
|
||||
|
||||
| message | who / when | meaning | reasons |
|
||||
|---|---|---|---|
|
||||
| `{ t:'vs', c:'role', v:'attacker'\|'defender'\|'random' }` | any human, lobby | choose your role; the other seat gets the opposite. `'random'` flips a coin (`random:true` in the `vs` message). The last choice wins. Clears every ready flag. | `phase` |
|
||||
| `{ t:'vs', c:'ready', v:boolean }` | any human, lobby | ready flag (the host does not need one; a computer is always ready) | `phase` |
|
||||
| `{ t:'vs', c:'bot', v:'attacker'\|'defender'\|null, skill?:0..1 }` | host, lobby | put a computer with that role in the **empty** seat (the human gets the opposite role); `null` removes it. `skill` defaults to 1. A human who joins in the lobby takes the seat over (the computer goes away). | `not_host`, `phase`, `full` (both seats already hold humans) |
|
||||
| `{ t:'vs', c:'start' }` | host, lobby | begin the match: every human except the host must be ready and online, two seats must be filled | `not_host`, `phase`, `no_opponent`, `offline`, `not_ready` |
|
||||
| `{ t:'vs', c:'next' }` | any human, roundover | go on to the next round; it starts when every human has sent it (a computer needs no vote) | `phase` |
|
||||
| `{ t:'vs', c:'rematch' }` | any human, matchover | vote for a new match with the **first round's roles swapped**, straight into the countdown; needs every human (and an opponent) | `phase`, `no_opponent` |
|
||||
|
||||
Game commands are `{ t:'cmd', c, ... }` as in co-op, with a per-mode whitelist (the sim checks the values and answers `{ ok:false, reason }`, which becomes
|
||||
a `reject` to the sender):
|
||||
|
||||
| role | `c` | fields |
|
||||
|---|---|---|
|
||||
| defender | `place` `sell` `upgrade` `target` | as in co-op (`type,x,y` / `id` / `id,lv?` / `id,mode`) |
|
||||
| defender | `tool` | `id:'scan'\|'patch'\|'repair'\|'quarantine'`, `x,y` (scan), `tid` (patch) |
|
||||
| attacker | `spawn` `stage` | `kind` (an enemy kind), `n?` (1..250, default 1), `gate?` (spawn index) |
|
||||
| attacker | `launch` | `gate?` |
|
||||
| attacker | `tech` | `id` (`armor`, `speed`, `health`, `regen`, `shield`, `stealth`, `crypt`) |
|
||||
| attacker | `ability` | `id:'emp'\|'decoy'\|'surge'\|'ddos'`, `tid?` (emp, decoy), `gate?` (decoy) |
|
||||
| nobody | `wave` `auto` `continue` | valid messages, always refused with `reason:'versus'` |
|
||||
|
||||
Types are checked before the sim sees anything: `kind` a string (at most 24 chars), `n` / `lv` / `gate` / `tid` integers (or null), `id` a string for
|
||||
`tool` / `ability` / `tech` and a number for `sell` / `upgrade` / `target`; anything else is malformed. Reasons: `role`, `credits` (`gold` for `place`),
|
||||
`cooldown`, `cap`, `max`, `bad_target`, `bad_kind`, `bad_cmd`, `empty` (nothing staged), `over`, `phase`, `frozen`, `versus`, plus the co-op ones.
|
||||
A reject echoes `x`, `y`, `id` (now also a string id) and `tid`. `ctl` `pause` / `speed` are **refused** in versus with `{ t:'reject', c:'pause'|'speed', reason:'versus' }`
|
||||
(a malformed `ctl` is still malformed), and `newgame` with `reason:'versus'` (replay with `rematch`).
|
||||
|
||||
### Messages, server -> client
|
||||
```
|
||||
{ t:'vs', phase, round, rounds, roles:{ '0':role, '1':role }, random, bot:{ slot, role, skill, name }|null, limit, ready:{ '0':bool, '1':bool }, frozen,
|
||||
countdown?, // countdown: whole seconds left
|
||||
next?:{ '0':bool, '1':bool }, nextIn?, // roundover: who has pressed next, seconds until the next round starts anyway
|
||||
result?, // roundover, matchover: the round that just ended
|
||||
history?, // as soon as a round has finished (also in round 2's countdown / playing, and after a reconnect)
|
||||
scores?, winner?, forfeit?, rematch? } // matchover
|
||||
{ t:'priv', role, ...sim.privateState(role) } // role-private data, see below
|
||||
```
|
||||
* `vs` is sent to everybody on **every change** (a role, a ready flag, the computer, a phase, each countdown second, a vote, a player joining, leaving, dropping or
|
||||
returning) and is part of `joined` as `joined.vs`. `frozen` is true while the round (or countdown, or result timer) waits for an offline human. `random` is
|
||||
true while the roles are still the coin flip. `bot.name` is `'Computer'`; its seat shows `ready: true`.
|
||||
* `result` = `{ winner:'attacker'|'defender', t, integrityLost, attacker:slot, defender:slot, forfeit? }`: the sim's own `vs.result` plus who sat where.
|
||||
`history` lists every finished round of the match as `{ round, roles, result }` (absent until the first round has finished, and in a new match), so the end screen can show both rounds side by side and a client that reconnects in round 2 can still show round 1. After round 2 the phase goes
|
||||
straight to `matchover` (it carries that round's `result`).
|
||||
* `scores` = `[{ slot, name, fellAt|null, integrityLost }]` per **attacking** performance: `fellAt` is the sim time the server fell in the round that seat attacked (null if it
|
||||
did not, or if the round was a forfeit); `integrityLost` is the integrity taken off in total (repairs do not give it back). `winner` is a slot, or `null` for a **draw**.
|
||||
Rule: the earlier fall wins; if only one seat felled the server it wins; if neither did, the one who took off more integrity; equal is a draw.
|
||||
* `forfeit` (matchover) is the seat that left (or whose grace period ran out); the other seat wins the match and, if a round was being played, that round.
|
||||
* **Private data** `priv`: `{ t:'priv', role, credits, income, tech, staged, cd, active }` for the attacker, `{ t:'priv', role, cd }` for the defender, to **each human only
|
||||
for its own current role**, at 4 Hz during `countdown` and `playing`, once when a round ends, on `sync`, and when a player (re)joins. The attacker's purse, tech, convoy
|
||||
composition and cooldowns are never sent to the defender, the defender's cooldowns never to the attacker (the test suite scans every frame both sockets receive).
|
||||
After a role swap the first `priv` of the new round replaces the old; clients should compare `priv.role` with their current role.
|
||||
* **No cursors, no map pings.** `cursor` and `mark` are valid messages in a versus room but are ignored: `snap.cur` is always `[]` and no `mark` is ever broadcast (an opponent must not see what you are
|
||||
about to build or target).
|
||||
* Snapshots are the co-op ones plus the shared block `vs: { t, lim, st }` (round clock, round limit, size of the staged convoy) and a 4th field `[id, tgt, kills, emp]`
|
||||
on the `tt` rows (seconds of EMP left). `state` / `joined.state` carry `mode:'versus'` and `limit`. `snap.s` is `'playing'` until the round ends, then `'over'`
|
||||
(`snap.pa` is always 0 and `snap.sp` always 1). The sim's `round` event arrives in `ev` as `{ e:'round', winner, t }`; the other new events are `emp`, `decoy`,
|
||||
`surge`, `ddos`, `quarantine`, `scan`, `repair`. Every round starts with a `{ t:'state', newgame:true }` (new sim, new tower list).
|
||||
* Size: the worst case is the alive cap (250 units) plus a built-up defence, about 38 bytes per unit row, roughly 10 KB per snapshot, 200 KB/s per client at 20 Hz
|
||||
(a test pins it below 16 KB). The `vs` and `priv` messages are under 500 bytes each.
|
||||
|
||||
### The computer seat
|
||||
`{ t:'vs', c:'bot', v:<role> }` (host, lobby) puts `NWBot` (`public/js/bot.js`) in the empty seat, with that role and `skill` 0..1. It runs **on the server**, inside the room loop,
|
||||
and plays through exactly the same door as a human: its commands are stamped with the seat's role and `by`, refused outside `playing` and while frozen, and it only sees the
|
||||
sim through the public API (`privateState` of its own role). Limits so that a computer seat cannot be used to burn CPU: it is asked to think at most 4 times per second of game
|
||||
time, only while `playing`; all the computers of the server together 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 a quiet period of `3d` for its room (so a heavy decision costs at most about a quarter of the loop); a bot that throws is switched off for the round. The computer seat is **not**
|
||||
a connection: a room with only a computer left is deleted, and in a running match a stranger who joins gets `full`. A solo player can also play a computer without the server:
|
||||
`NW.LocalController` with `mode:'versus'` (same `vs` / `priv` shapes, see `controllers.js`).
|
||||
|
||||
### Disconnects, forfeits and hosts
|
||||
* **Freeze.** While *any* human seat is offline the countdown, the round and the result timer stand still (co-op ticks while anyone is online; versus must not let one side keep
|
||||
building or spawning against an absent opponent) and commands get `reason:'frozen'`. The player can come back with the same `pid` within `graceMs` (60 s): `joined` carries the
|
||||
current `vs`, a `priv` follows, `frozen` becomes false for everybody.
|
||||
* **Forfeit.** When the grace period runs out, or a player sends `leave`, the one who stays wins: in `playing` the current round is awarded to them (the sim ends it with
|
||||
the `round` event, `result.forfeit:true`), between rounds the match is over with the finished rounds in `history`; either way the phase becomes `matchover` with
|
||||
`forfeit:<leaver's seat>` and `winner:<the other seat>`. A forfeit never counts as "the server fell". After that the remaining player is host (migration as in co-op) and
|
||||
the room stays in `matchover`: a new human can take the empty seat (`rematch` then needs both votes); the computer seat can only be set in the lobby, so a player who wants a
|
||||
computer instead creates a new room.
|
||||
* A leave or a timed-out grace period in the **lobby** just changes the seats (ready flags are cleared); in the **countdown of round 1** it sends the room back to the lobby (no match
|
||||
had started); in the countdown of round 2 it is a forfeit.
|
||||
* The host migrates exactly as in co-op; the host's powers are `bot` and `start`. A guest can pick roles and ready up.
|
||||
* Server options for tests: `vsCountdownMs` (3000) and `vsNextMs` (30000) in `createServer`.
|
||||
|
|
|
|||
|
|
@ -1,5 +1,10 @@
|
|||
# Versus mode: attack vs defend ("play as the Internet")
|
||||
|
||||
> **Status 2026-10-11:** implemented end to end (sim + bots, server + protocol, client UI) but **not QA'd and not balanced**. With the shipped numbers
|
||||
> the attacker bot wins ~100% of rounds on every map; the cheap 3-credit swarm units (botnet, spam) are the dominant lever (botnet 8 and spam 6
|
||||
> flips it to ~0%; botnet 6 / spam 4 / worm 8 lands near 75%). The remaining planned steps (balance pass with `tools/versus.js`, independent QA with
|
||||
> two real browsers) are in `docs/workflows/versus-full.js` (the BALANCE and QA prompts at its end).
|
||||
|
||||
Requested 2026-10-10. One player **defends** (builds the maze and turrets, as today); the other **attacks** (earns credits over
|
||||
time, spends them on spawning packets, upgrades and sabotage). Same board, same rules, one authoritative simulation per room.
|
||||
Decisions made with the user: timed rounds then swap roles; attacker abilities *and* defender counter-tools; a computer
|
||||
|
|
@ -72,3 +77,31 @@ prioritises for 5 s; *Surge* all units +40% speed for 6 s; *DDoS* all turrets fi
|
|||
6. **e2e**: two browsers play a round each way; one bot match.
|
||||
|
||||
Depends on the content wave (new enemy kinds become shop items) and on the difficulty/economy constants, so it comes after them.
|
||||
|
||||
## Client as built (2026-10-11)
|
||||
|
||||
All of it lives in `public/js/versus.js` (`NW.Versus`, created by `main.js`; with no versus game running it does nothing, so solo and co-op are untouched) plus the
|
||||
`#vsSetup`, `#vsRoom` and `#vsEnd` dialogs in `index.html`, a block at the end of `style.css`, versus cues in `render.js` and the new sounds in `audio.js`.
|
||||
|
||||
* **Entering.** Menu -> *Versus* -> setup dialog: your role (Attack / Defend / Random), round length (8 / 12 / 16 min, from `TD.VS.LIMITS`), computer skill (Easy 0.35 /
|
||||
Normal 0.7 / Hard 1). *Play the computer* starts a `LocalController` match (no server, no lobby: it starts in its 3 s countdown). *Create room* / *Join* (code) go to the
|
||||
server; an invite link (`?room=`) still opens the co-op lobby dialog and works for a versus room too (the room says what it is).
|
||||
* **Room (online lobby).** Seats with role badge and ready flag, your role (Attack / Defend / Random), host-only *Opponent: A friend / Computer*, host *Start match* (disabled with the
|
||||
reason until the opponent is online and ready), guest *I'm ready*. Then a countdown card on the stage ("Round 1 of 2: YOU ATTACK"), round over (`#vsEnd`, both rounds side by side,
|
||||
*Next round*), match over (the server's verdict from `vs.winner` / `vs.forfeit`, never recomputed; *Rematch (roles swap)*). A frozen room (opponent offline) shows a PAUSED card.
|
||||
* **Defender HUD.** Today's tower palette, plus a tools row under it: Scan (tap, then tap the map; radius ring follows the pointer), Patch (re-enables the selected disabled tower, else
|
||||
the one with most EMP left), Repair, Quarantine (second tap to confirm, like every action of 150+ credits). Each has a cooldown ring + seconds and greys out when it cannot be afforded.
|
||||
* **Attacker HUD.** The palette becomes the unit shop (every `TD.ENEMY_ORDER` kind with `buyCost`, price shown for the chosen quantity; a tap buys; fewer is bought when credits fall short),
|
||||
then a row `[x1|x5|x10] [Send|Stage] [Any gate|Gate n] [LAUNCH n + convoy composition]`, the four abilities with cooldown rings (EMP: tap it, then a tower; or select a tower and use the
|
||||
button in its action bar), and the tech row (7 upgrades, level pips, price doubling per level). Credits (smoothly run forward from the 4 Hz `priv` data) and income are in the top bar,
|
||||
units alive and the defender's credits in a pill on the stage. Tapping a gateway (or the gate button) chooses where packets enter; units appearing at a gateway pulse it for both sides.
|
||||
Keys: 1-9 buy that unit, Space launches. Optimistic local bookkeeping (credits, cooldown start) is overwritten by the next `priv`.
|
||||
* **Layout.** Stacked layouts: the dock (convoy row + abilities / tools) is pinned to the bottom of the side panel and the board gets less height (`V.minSide`); the tech row scrolls like the
|
||||
shop. Short landscape: the shop and tech are scrolling grids in the 200 px column, the abilities keep four columns as icon + cost.
|
||||
* **Rendering.** EMP'd towers are dimmed with hazard stripes, sparks and a draining arc; armed EMP outlines every target; decoys are dashed-ringed and half transparent (from the `decoy`
|
||||
event on the wire, `m.decoy` locally); the attacker sees its own stealth (cloak shimmer for the first seconds) and shield (ring) because the wire carries neither (inferred from its tech
|
||||
levels when the unit first appears, exact in a local match); Surge (orange edge), DDoS (violet scan lines), Quarantine (icy tint) and Scan zones are drawn for both sides. The defender
|
||||
deliberately sees no stealth or shield cue (it does not know the attacker's tech).
|
||||
* **Known limits.** A local match cannot be paused (versus has no pause; `LocalController.ctl` ignores it), so opening the menu in a computer match leaves the round running behind it.
|
||||
Presets (Rush, Swarm, ...) from the design are not in the UI yet; the x1/x5/x10 selector covers most of it.
|
||||
|
||||
|
|
|
|||
109
docs/workflows/versus-full.js
Normal file
109
docs/workflows/versus-full.js
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
export const meta = {
|
||||
name: 'netwall-wave4-versus-mode',
|
||||
description: 'Wave 4: attack-vs-defend multiplayer: sim rules + bots, then server/protocol, then client UI, then bot-vs-bot balance, then independent QA (strictly sequential, one owner at a time)',
|
||||
phases: [
|
||||
{ title: 'Sim', detail: 'versus rules, economy, abilities, bots (pure, tested)' },
|
||||
{ title: 'Server', detail: 'rooms, roles, rounds, protocol, bot seat' },
|
||||
{ title: 'Client', detail: 'lobby, role-aware HUD, attacker shop, tools, phone-first' },
|
||||
{ title: 'Balance', detail: 'bot-vs-bot matches, time-boxed' },
|
||||
{ title: 'QA', detail: 'two real browsers play a full match' },
|
||||
],
|
||||
}
|
||||
|
||||
const SP = '/tmp/claude-1000/-home-jav-git-towerdefence/417476cf-3c23-4caf-be25-6f9a83ee50b9/scratchpad'
|
||||
const ROOT = '/home/jav/git/towerdefence'
|
||||
|
||||
const COMMON = `
|
||||
PROJECT: "Netwall", an HTML5 maze-building tower defence game: solo in the browser, two-player co-op through a Node server (ws). Repo: ${ROOT} (git repo; do NOT run git commit/push or checkout/reset/stash: the lead commits).
|
||||
Read ${ROOT}/README.md, ${ROOT}/docs/NEXT.md, ${ROOT}/docs/PROTOCOL.md and ESPECIALLY ${ROOT}/docs/VERSUS.md (the design the user approved: attack-vs-defend, timed rounds then swap roles, attacker abilities AND defender counter-tools, a computer opponent for either side).
|
||||
Layout: public/ (index.html, css/style.css, js/sim.js shared PURE rules (browser solo + Node server), js/controllers.js Local+Remote, js/render.js, js/main.js UI/input/lobby, js/audio.js, sw.js), server/ (Node + ws), test/ (node:test; ONLY real test files), e2e/ (Playwright scenarios, "npm run e2e [-- filter]"), tools/bot.js (headless defender bot used for balancing).
|
||||
ENVIRONMENT: no system Node. First: source ${SP}/pwenv.sh. playwright-core is in ${ROOT}/node_modules. Launch with chromium.launch({args:['--no-sandbox']}). Examples: ${ROOT}/e2e/scenarios/*.js. Look at screenshots with the Read tool. Real server: cd ${ROOT} && PORT=<yours> HOST=127.0.0.1 node server/index.js (serves public/ too). Use ONLY your port range; KILL every server/browser you start by port (ss -ltnp | grep :PORT), never a broad pkill. Scratch work in ${SP}/wave4/<key>/, never in the repo.
|
||||
Compatibility rules: (1) sim.js stays PURE and DOM-free; (2) the existing co-op/solo behaviour and wire format must keep working unchanged (versus is an additional mode); (3) never assume 3 tower levels, a fixed tower/enemy count or exactly 2 maps; (4) no new dependencies, vanilla JS, classic scripts (no ES modules) in public/; (5) every new rule has a unit test, every new UI behaviour an e2e assertion that FAILS without it; (6) phones first: all new controls must be reachable by thumb on 320x568, 390x844 and 667x375, in the same compact/bar patterns the UI already uses (read public/css/style.css and main.js layoutBars/towerbar code first, and extend the 22-layout matrix e2e/scenarios/05-layout-matrix.js for new controls).
|
||||
CURRENT STATE you build on (all of this exists and is tested): 7 maps, 9 towers (wall, filter, ids, mortar, throttle, arc, sandbox, balancer, uplink; the Uplink has 4 levels and gets dearer per owned unit via TD.priceFor/upgradePrice and a per-tower price multiplier 'pm' carried as the 9th field of tower rows), 9 enemy kinds in TD.ENEMY_ORDER (ping, worm, trojan, spam, ghost, rootkit, daemon healer, proxy shielded, botnet swarm) each with a buyCost, an Easy/Normal/Hard difficulty option for solo and co-op (versus IGNORES difficulty: units use base stats x attacker tech, no wave hp scaling), idempotent upgrade/wave commands ('stale'), a shared priceOf in the UI, 17 e2e scenarios and 156 unit tests, and phone UI patterns (layoutBars, #confirm and tower bars, compact overlays with pinned footers, role=dialog handling). Read the code before extending it; do not undo any of it.
|
||||
MACHINE NOTE: the box is shared and slow under load; e2e timing checks can flake: rerun a failing scenario alone before concluding anything; the full layout matrix takes ~8 minutes.
|
||||
Aim for about 75 minutes of focused work per agent; do not gold-plate; "node --test" and "npm run e2e" must be green when you finish.
|
||||
|
||||
BINDING CONTRACT between the agents (names are exact; extend, do not rename):
|
||||
SIM
|
||||
- new TD.Sim({ map, mode: 'versus', limit: 720 }). In versus: no automatic waves, startWave refused, no clear bonus, no win-wave; hp scaling by wave is off (units use base stats x attacker tech); state stays 'playing' until the round ends; then sim.state = 'over' and sim.vs.result = { winner: 'attacker'|'defender', t: <seconds>, integrityLost: n }.
|
||||
- sim.cmd({ c, role, by, ...fields }) where role is 'defender' | 'attacker' (the server fills role from the seat; the sim REFUSES cross-role commands with reason 'role'). Solo/co-op commands (no role) behave exactly as before.
|
||||
- defender commands: place, sell, upgrade, target (as today) and { c:'tool', id:'scan'|'patch'|'repair'|'quarantine', x?, y?, tid? }.
|
||||
- attacker commands: { c:'spawn', kind, n?, gate? } buy and release now; { c:'stage', kind, n? } pay now, hold in the convoy; { c:'launch', gate? } release the convoy as a ~3 s stream; { c:'tech', id } buy the next level; { c:'ability', id:'emp'|'decoy'|'surge'|'ddos', tid?, gate? }. 'gate' is a spawn index (default: round robin).
|
||||
- Every command returns { ok, reason? }. Reasons used: 'role','credits','cooldown','cap','max','bad_target','over'.
|
||||
- sim.snapshot() gains a SHARED block 'vs': { t, lim, st /*staged count*/ } only. Role-private data comes from sim.privateState(role) -> attacker: { credits, income, tech:{armor,speed,health,regen,shield,stealth,crypt}, staged:[[kind,n]], cd:{emp,decoy,surge,ddos}, active:{surge,ddos} } ; defender: { cd:{scan,patch,repair,quarantine} }. fullState() carries mode, limit and map as today.
|
||||
- ENEMIES entries have 'buyCost' (already added to every enemy kind by an earlier agent; verify).
|
||||
- events: 'spawn' not needed; add { e:'emp', id }, { e:'surge' }, { e:'ddos' }, { e:'quarantine' }, { e:'scan', x, y }, { e:'repair' }, { e:'round', winner, t } as needed (small objects).
|
||||
BOTS (public/js/bot.js, UMD like sim.js: window.NWBot / module.exports): NWBot.create(sim, role, { seed, skill }) -> { think(dt) } driven ONLY through sim.cmd/sim.preview/sim.privateState (the same API humans use). Defender bot: a productionised, lighter version of the maze+turret logic in tools/bot.js (reuse its ideas, keep it < ~400 lines, no heavy analytic model needed). Attacker bot: a budgeted spender that watches the tower mix (flyers when there is no anti-air, armoured units against filters/arcs, healers behind trojans), saves credits for convoys, buys tech, uses abilities sensibly.
|
||||
PROTOCOL (see docs/PROTOCOL.md; add a "Versus" section)
|
||||
- join/create takes { mode:'coop'|'versus' (default coop), limit?:480|720|960, rounds?: 2 }.
|
||||
- versus lobby messages (client -> server): { t:'vs', c:'role', v:'attacker'|'defender'|'random' }, { t:'vs', c:'ready', v:boolean }, { t:'vs', c:'bot', v:'attacker'|'defender'|null } (host: put a computer in the empty seat with that role), { t:'vs', c:'start' } (host, when everyone is ready), { t:'vs', c:'next' } (continue after a round), { t:'vs', c:'rematch' }.
|
||||
- server -> client: { t:'vs', phase:'lobby'|'countdown'|'playing'|'roundover'|'matchover', round:1|2, rounds, roles:{ '<slot>': 'attacker'|'defender' }, bot:{ slot?, role }|null, countdown?:seconds, limit, result?:{...}, scores?:[{slot, name, fellAt|null, integrityLost}] } on every change; role-private data { t:'priv', role, ...sim.privateState(role) } to each human at 4 Hz while playing; snapshots as today with the shared 'vs' block.
|
||||
- commands arrive as { t:'cmd', c:..., ...} exactly as today; the server adds role from the seat. ctl pause/speed are rejected in versus ({t:'reject', reason:'versus'}).
|
||||
- disconnect: the round freezes for the 60 s grace, then the remaining player wins the round.
|
||||
MATCH RULES: two rounds, roles swapped after round 1 (host's first role choice, or random); a round ends when integrity reaches 0 (attacker wins, time recorded) or the timer hits the limit (defender wins). Match winner = the player whose attacking round ended earlier; if neither felled the server, the player who took off more integrity; else a draw.
|
||||
ECONOMY (starting numbers, tuned later by the balance agent through constants in one VS table at the top of sim.js): attacker start 150, income 4/s + 0.02/s per second elapsed, lifetime bonus buyCost*0.004 per second alive capped at 50% of buyCost per unit, leak pays back the unit's buyCost; caps 250 units alive / 200 staged; defender start 250, trickle 2/s, kill reward round(buyCost*0.4); tech levels: armor +1 (5 levels), speed +8% (5), health +15% (5), regen +1% max hp/s (3), shield +40 per level (3), stealth: towers cannot target a unit for its first 1/1.5/2 s on the map (3 levels), crypt: resists slows 20/40/60% (3); costs 100*2^level. Abilities (credits, cooldown): emp (disable one tower 6 s; 80cr, 20 s), decoy (a harmless unit every tower prioritises 5 s; 60cr, 25 s), surge (all units +40% speed 6 s; 120cr, 40 s), ddos (all towers fire 40% slower 4 s; 200cr, 70 s). Defender tools: scan (clear emp + reveal stealth in radius 4 for 3 s; 40cr, 15 s), patch (instantly re-enable one tower; 30cr, 8 s), repair (+3 integrity up to max; 120cr, 30 s), quarantine (all units frozen 2 s; 150cr, 60 s).`
|
||||
|
||||
const RESULT = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
summary: { type: 'string' },
|
||||
implemented: { type: 'array', items: { type: 'object', properties: { what: { type: 'string' }, details: { type: 'string' } }, required: ['what', 'details'] } },
|
||||
contractChanges: { type: 'array', items: { type: 'string' } },
|
||||
filesChanged: { type: 'array', items: { type: 'string' } },
|
||||
testsAdded: { type: 'array', items: { type: 'string' } },
|
||||
unitTests: { type: 'string' },
|
||||
e2e: { type: 'string' },
|
||||
notes: { type: 'string' },
|
||||
},
|
||||
required: ['summary', 'implemented', 'unitTests', 'e2e'],
|
||||
}
|
||||
|
||||
const SIM = `${COMMON}
|
||||
YOUR BRIEF (agent "vs-sim", ports 8610-8619). You OWN public/js/sim.js, public/js/bot.js (new), test/sim-versus.test.js (new), tools/ additions. Implement the SIM and BOTS part of the contract: versus mode in the Sim (economy, spawn/stage/launch, tech, abilities, defender tools, role checks, round timer and result, private state, snapshot vs block, events), the shared VS constants table at the top, and public/js/bot.js with a defender bot and an attacker bot. Also add a headless runner tools/versus.js: "node tools/versus.js --maps open,twin --limit 600 --seeds 6 [--attacker-skill 1 --defender-skill 1]" that plays bot-vs-bot rounds and prints a table (who won, time to fall, integrity lost, credits spent, units spawned) so the balance agent can tune later; keep it fast (all CPU cores via worker threads or child processes like tools/bot.js).
|
||||
Unit tests (test/sim-versus.test.js) must cover: role refusal both ways, credits and caps, spawn vs stage vs launch, lifetime bonus and its cap, leak payback, every tech level effect on a spawned unit (armor, speed, health, regen, shield, stealth: towers skip a stealthed unit; crypt), each ability and tool incl. cooldowns and costs (emp disables a tower for its duration, decoy is prioritised and harmless, surge, ddos slows fire, scan reveals/clears, patch, repair never exceeds max, quarantine freezes), round end both ways and the result object, privateState shape, snapshot JSON round trip with the vs block, no regression of solo/co-op (existing tests keep passing), and bot smoke tests (a bot round runs to completion without throwing and without illegal commands on all maps).
|
||||
Keep co-op/solo behaviour byte-identical when mode is not 'versus'.`
|
||||
|
||||
const SERVER = (prev) => `${COMMON}
|
||||
YOUR BRIEF (agent "vs-server", ports 8620-8629). The sim agent finished (report: ${JSON.stringify(prev)}). You OWN server/*, test/server.test.js (and new test files for versus), docs/PROTOCOL.md, docs/DEPLOY.md only if needed, and public/js/controllers.js ONLY for the RemoteController message handling of the new messages (vs / priv) and exposing them (ctrl.vs, ctrl.priv, events 'vs' and 'priv'), plus LocalController support for a local versus game against a bot (ctrl.kind 'local', the human has a role and NWBot plays the other seat; no pause/speed). Implement the SERVER and PROTOCOL part of the contract: room mode versus, the lobby/ready/countdown/round/roundover/matchover state machine, seats and roles (random/choose/swap), the optional bot seat (server-side NWBot ticking with the room loop, think() at about 4 Hz, commands go through the same validated path as humans), role added to commands from the seat and cross-role refusal surfaced as reject, ctl pause/speed rejected, private data messages at 4 Hz, grace/forfeit rules, host migration, rematch, disconnect during countdown/roundover, snapshot size sanity, and docs/PROTOCOL.md "Versus" section. Security: a client can never see the other role's private data, never send commands for the other role, malformed vs messages count as malformed, and a bot seat cannot be used to run unbounded work (cap thinking time per tick).
|
||||
INTERRUPTED EARLIER ATTEMPT: a previous run of this agent was cut off by an account spend limit in the middle of its work. The working tree already contains its UNVERIFIED partial work: server/versus.js, test/server-versus.test.js, test/controllers-versus.test.js, edits to server/room.js, server/index.js, public/js/controllers.js and docs/PROTOCOL.md; "node --test" currently shows about 4 failing tests because of it. Start by reading "git status" and "git diff", understand what is there, review it critically against the contract (do not trust it), keep what is good, fix what is wrong, finish what is missing, and make everything green. Do not duplicate files.
|
||||
Tests: protocol tests with raw ws clients for the full match (two humans, and human + bot), role leaks, forged role, reconnect mid-round, forfeit, rematch, and that co-op rooms behave exactly as before.`
|
||||
|
||||
const CLIENT = (prev) => `${COMMON}
|
||||
YOUR BRIEF (agent "vs-client", ports 8630-8639). The sim and server agents finished (reports: sim ${JSON.stringify(prev.sim)}; server ${JSON.stringify(prev.server)}). You OWN public/index.html, public/css/style.css, public/js/main.js, public/js/render.js, public/js/audio.js (new sfx) and e2e/. Implement the CLIENT part: (1) lobby: mode choice Co-op vs Versus, role choice (attacker / defender / random), round time limit, 'play against computer' (a bot in the other seat; also a SOLO versus game that needs no server using LocalController), ready/start/countdown, round-over and match-over screens (both rounds side by side, who won, rematch); the lobby/menu slots #menuOpts and #roomList exist (reserved earlier) but are not required for this; (2) ROLE-AWARE HUD: the defender keeps today's build palette plus a counter-tools bar (scan, patch, repair, quarantine with cooldown rings and costs) and the round timer; the attacker gets: the palette becomes the UNIT SHOP (all enemy kinds with buyCost, tap = buy 1, a x1/x5/x10 quantity selector, a Send-now/Stage toggle), a Convoy readout with a big LAUNCH button, a tech panel (7 upgrades with level pips and cost), an abilities bar (emp: tap then tap a tower; decoy; surge; ddos) with cooldown rings, the credits + income/s readout, units alive, round timer; the attacker cannot place towers; the attacker sees the defender's board live; (3) rendering for versus: units already render; add shield/stealth/decoy/emp visuals (a disabled tower looks disabled), surge/ddos/quarantine screen cues, spawn pulses at gates the attacker chooses (an attacker can tap a gateway to choose it); (4) phone-first layouts using the existing bar patterns (attacker shop must scale to 9+ unit kinds, convoy/launch always reachable), add the new controls to the 22-layout matrix (e2e/scenarios/05-layout-matrix.js) with the same objective reachability assertions; (5) sounds for the new actions; (6) help text for versus; (7) e2e: a scenario with TWO browsers (one attacker, one defender, real server) that plays a full short round (limit 60 s via a test option or server option), checks role-private data does not leak into the other client, the swap, the match result, plus a solo-vs-bot scenario; (8) keep co-op and solo untouched.`
|
||||
|
||||
const BALANCE = (prev) => `${COMMON}
|
||||
YOUR BRIEF (agent "vs-balance", ports 8640-8649). All parts exist now (reports: ${JSON.stringify(prev)}). TIME-BOX HARD: at most 12 runs of tools/versus.js (each run in the background with a wait; do not babysit), then stop. You OWN only the VS constants table at the top of public/js/sim.js, the enemy buyCost values, and public/js/bot.js tuning. Goal: neither side wins more than about 60% of rounds on any of the 7 maps when two equally skilled bots play (limit 720 s); the defender must be able to survive a sensible attacker for a good while on easy maps; the attacker's lifetime bonus must matter but not snowball; abilities and tools must be used by the bots and matter. Report a before/after table and every constant you changed. Keep all tests green.`
|
||||
|
||||
const QA = (all) => `${COMMON}
|
||||
YOUR BRIEF (independent QA, ports 8650-8659). Versus mode was built in 4 steps: ${JSON.stringify(all)}.
|
||||
1. Run "cd ${ROOT} && node --test" and "cd ${ROOT} && npm run e2e" yourself (the layout matrix takes ~6 minutes); report exact results.
|
||||
2. PLAY a full match with TWO real browsers (a desktop and a 390x844 phone with CDP touch) on the real server: humans in both roles, then human + bot in both roles, then solo versus bot with no server. Look at screenshots (Read tool) of every state: lobby, countdown, attacker shop (all unit kinds), staging and launch, tech, abilities, defender tools, round over, match over. Judge thumb reach, clarity, clutter, and whether a first-time attacker would understand what to do.
|
||||
3. ATTACK the implementation: attacker sends defender commands and vice versa (raw ws), forged role, spamming spawn to hit caps, negative/huge n, NaN, staging 10^6 units, launching an empty convoy, using an ability on a dead tower, disconnect mid-round (both sides), reconnect, host leaves, rematch spam, three clients in a versus room, a coop client joining a versus room. Check the defender can never read attacker credits/composition from any message, the server stays responsive with a bot seat and 250 units, and snapshot size stays sane.
|
||||
4. Review "git diff"/"git status" for sloppy code, protocol/doc/code mismatches, leftover debug.
|
||||
Fix trivial regressions yourself (say what); report bigger issues with exact repro. No new features.`
|
||||
|
||||
phase('Sim')
|
||||
const sim = await agent(SIM, { label: 'vs-sim', phase: 'Sim', schema: RESULT })
|
||||
phase('Server')
|
||||
const server = await agent(SERVER(sim), { label: 'vs-server', phase: 'Server', schema: RESULT })
|
||||
phase('Client')
|
||||
const client = await agent(CLIENT({ sim, server }), { label: 'vs-client', phase: 'Client', schema: RESULT })
|
||||
phase('Balance')
|
||||
const balance = await agent(BALANCE({ sim, server, client }), { label: 'vs-balance', phase: 'Balance', schema: RESULT })
|
||||
phase('QA')
|
||||
const qa = await agent(QA({ sim, server, client, balance }), {
|
||||
label: 'qa', phase: 'QA',
|
||||
schema: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
unitTests: { type: 'string' }, e2e: { type: 'string' },
|
||||
regressions: { type: 'array', items: { type: 'string' } },
|
||||
changedByQa: { type: 'array', items: { type: 'string' } },
|
||||
securityFindings: { type: 'array', items: { type: 'string' } },
|
||||
uxProblems: { type: 'array', items: { type: 'string' } },
|
||||
verdict: { type: 'string' },
|
||||
},
|
||||
required: ['unitTests', 'e2e', 'verdict'],
|
||||
},
|
||||
})
|
||||
return { sim, server, client, balance, qa }
|
||||
Loading…
Add table
Add a link
Reference in a new issue