From 2e7b05bdad8dacfd6c7064bef1b962ae2b6c6915 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 04:02:15 +0000 Subject: [PATCH 1/3] Night 1: private 3-node testnet fixture (deploy/night) (#16) LAN-only 3-node testnet compose, paced miner and helper script under deploy/night. Co-Authored-By: Claude Opus 5.5 --- deploy/night/README.md | 18 +++++++ deploy/night/compose.lan.yaml | 24 +++++++++ deploy/night/mine.ts | 99 +++++++++++++++++++++++++++++++++++ deploy/night/testnet.sh | 32 +++++++++++ 4 files changed, 173 insertions(+) create mode 100644 deploy/night/README.md create mode 100644 deploy/night/compose.lan.yaml create mode 100644 deploy/night/mine.ts create mode 100755 deploy/night/testnet.sh diff --git a/deploy/night/README.md b/deploy/night/README.md new file mode 100644 index 0000000..ed73676 --- /dev/null +++ b/deploy/night/README.md @@ -0,0 +1,18 @@ +# Night 1 private testnet (sim-testnet) + +A 3-node **testnet-only** fixture on poweredge-r350. It is reachable on the LAN only, and uses the Docker project `wikideck-night`. + +| node | URL | +|---|---| +| node-a | http://192.168.1.32:3101 | +| node-b | http://192.168.1.32:3102 | +| node-c | http://192.168.1.32:3103 | + +- `compose.lan.yaml` overrides only the published ports (bound to `192.168.1.32`, never `0.0.0.0`) and `PUBLIC_ORIGIN`. It changes nothing in consensus or the image. +- `mine.ts` is a multi-worker native RandomX miner. It runs inside the `wikideck:testnet` image, which ships the native engine, so the host needs no cmake. + - It mines to 4 disposable wallets (alice, bob, carol, dave) and writes chain-bound encrypted browser backups to `$STATE_DIR/wallets/`. + - It never changes consensus code. Speed comes from the protocol's own testnet parameters: the initial target accepts 1/16 of hashes, and each 10-block retarget at most quadruples the difficulty. + - Each template costs several Wikipedia API calls, and Wikipedia rate-limits our egress IP. The miner therefore paces templates (`MIN_GAP`, default 45 s) and backs off exponentially on failure. +- `testnet.sh` has `up`, `mine N [workers]`, `status` and `down`. Run it from the repo root on a checkout of the integration branch. `up` rebuilds the image from that checkout; the ledgers persist in the named volumes. + +Never point this at mainnet or the live `wikideck` namespace. diff --git a/deploy/night/compose.lan.yaml b/deploy/night/compose.lan.yaml new file mode 100644 index 0000000..973bd1d --- /dev/null +++ b/deploy/night/compose.lan.yaml @@ -0,0 +1,24 @@ +# sim-testnet override: publish the fixture on r350's LAN address only (not 0.0.0.0). +# Game-mode env (modes team, #6) is inert until night/modes/hosting merges. +services: + node-a: + ports: !override ["192.168.1.32:3101:3001"] + environment: + PUBLIC_ORIGIN: http://192.168.1.32:3101 + WIKIDECK_MODES: classic,trending + WIKIDECK_GAME_OPERATOR: Testnet A + WIKIDECK_GAME_PEERS: http://192.168.1.32:3102,http://192.168.1.32:3103 + node-b: + ports: !override ["192.168.1.32:3102:3001"] + environment: + PUBLIC_ORIGIN: http://192.168.1.32:3102 + WIKIDECK_MODES: draft + WIKIDECK_GAME_OPERATOR: Testnet B + WIKIDECK_GAME_PEERS: http://192.168.1.32:3101,http://192.168.1.32:3103 + node-c: + ports: !override ["192.168.1.32:3103:3001"] + environment: + PUBLIC_ORIGIN: http://192.168.1.32:3103 + WIKIDECK_MODES: classic,trending,draft + WIKIDECK_GAME_OPERATOR: Testnet C + WIKIDECK_GAME_PEERS: http://192.168.1.32:3101,http://192.168.1.32:3102 diff --git a/deploy/night/mine.ts b/deploy/night/mine.ts new file mode 100644 index 0000000..96f9e4e --- /dev/null +++ b/deploy/night/mine.ts @@ -0,0 +1,99 @@ +// sim-testnet: multi-worker native RandomX miner for the PRIVATE wikideck-night testnet. +// Runs inside the wikideck:testnet image (which ships the native engine). Testnet only. +// Usage: node --experimental-strip-types /night/mine.ts +import { mkdirSync, readFileSync, writeFileSync, existsSync, appendFileSync } from 'node:fs'; +import { randomInt, webcrypto } from 'node:crypto'; +import { RandomX } from '/app/server/testnet/randomx.ts'; +import { CHAIN_ID, sha256, miningBlob, mintId, blockSchema, address } from '/app/server/testnet/consensus.ts'; +import { blockClaimMessage, NETWORK, type MiningTemplate, type TestnetBlock } from '/app/shared/testnet.ts'; +import { encryptWallet } from '/app/shared/wallet-backup.ts'; + +if (!NETWORK.includes('testnet')) throw new Error('testnet only'); +const blocks = Number(process.argv[2] ?? 45), workers = Number(process.argv[3] ?? 4); +if (!(workers >= 1 && workers <= 8)) throw new Error('1..8 workers'); +const NODES = ['http://node-a:3001', 'http://node-b:3001', 'http://node-c:3001']; +const WALLET_NAMES = ['alice', 'bob', 'carol', 'dave']; +const PASSWORD = 'wikideck-night-testnet'; +const STATE = process.env.STATE_DIR ?? '/state'; +const dir = `${STATE}/wallets`; +mkdirSync(dir, { recursive: true }); +const subtle = webcrypto.subtle; + +type W = { name: string; address: string; publicKey: string; privateKey: CryptoKey }; +async function loadOrCreate(name: string): Promise { + const keyFile = `${dir}/${name}.jwk.json`; + let jwk: JsonWebKey; + if (existsSync(keyFile)) jwk = JSON.parse(readFileSync(keyFile, 'utf8')); + else { + const kp = await subtle.generateKey({ name: 'ECDSA', namedCurve: 'P-256' }, true, ['sign', 'verify']) as CryptoKeyPair; + jwk = await subtle.exportKey('jwk', kp.privateKey); + writeFileSync(keyFile, JSON.stringify(jwk), { mode: 0o600 }); + } + const privateKey = await subtle.importKey('jwk', jwk, { name: 'ECDSA', namedCurve: 'P-256' }, true, ['sign']); + const pubJwk = { kty: jwk.kty, crv: jwk.crv, x: jwk.x, y: jwk.y }; + const pub = await subtle.importKey('jwk', pubJwk, { name: 'ECDSA', namedCurve: 'P-256' }, true, ['verify']); + const publicKey = Buffer.from(await subtle.exportKey('spki', pub)).toString('base64'); + const w = { name, address: address(publicKey), publicKey, privateKey }; + const backupFile = `${dir}/${name}.backup.json`; + if (!existsSync(backupFile)) writeFileSync(backupFile, JSON.stringify(await encryptWallet(privateKey, publicKey, PASSWORD), null, 2)); + return w; +} +const wallets = await Promise.all(WALLET_NAMES.map(loadOrCreate)); +writeFileSync(`${dir}/addresses.json`, JSON.stringify(Object.fromEntries(wallets.map(w => [w.name, w.address])), null, 2)); +console.log(`chain ${CHAIN_ID}; wallets: ${wallets.map(w => `${w.name}=${w.address.slice(0, 12)}`).join(' ')}`); + +async function api(node: string, path: string, body?: unknown) { + const r = await fetch(node + path, { method: body ? 'POST' : 'GET', redirect: 'error', signal: AbortSignal.timeout(60000), + headers: body ? { 'Content-Type': 'application/json' } : {}, body: body ? JSON.stringify(body) : undefined }); + const data = await r.json(); + if (!r.ok) throw new Error(data.error ?? `HTTP ${r.status}`); + return data; +} +const engines = Array.from({ length: workers }, () => new RandomX()); +const close = () => { for (const e of engines) e.close(); }; +process.once('SIGTERM', () => { close(); process.exit(0); }); + +let accepted = 0, round = 0, fails = 0; +// Each template costs several Wikipedia API calls, and Wikipedia rate-limits this egress IP: +// pace templates (>= MIN_GAP s apart) and back off exponentially on failure. +const MIN_GAP = Number(process.env.MIN_GAP ?? 45), sleep = (s: number) => new Promise(r => setTimeout(r, s * 1000)); +let lastTemplate = 0; +try { + while (accepted < blocks) { + const wait = lastTemplate + MIN_GAP * 1000 - Date.now(); if (wait > 0) await sleep(wait / 1000); + lastTemplate = Date.now(); + const node = NODES[round % NODES.length], w = wallets[accepted % wallets.length]; round++; + let template: MiningTemplate; + try { template = await api(node, '/api/mining/template', { owner: w.address, publicKey: w.publicKey }); fails = 0; } + catch (e) { fails++; const b = Math.min(60 * 2 ** (fails - 1), 600); console.error(`template ${node}: ${(e as Error).message} (fail ${fails}, backoff ${b}s)`); await sleep(b); continue; } + const h = template.header; if (h.chainId !== CHAIN_ID) throw new Error('wrong chain'); + const started = Date.now(); let attempts = 0; let found: { hash: string; nonce: number } | null = null; + let base = randomInt(0, 2 ** 40); const BATCH = 64; + while (!found) { + const results = await Promise.all(engines.map((e, i) => { + const hdr = { ...h, nonce: base + i * BATCH }; + return e.mine(h.key, miningBlob(hdr), h.target, 32, BATCH); + })); + attempts += BATCH * workers; base += BATCH * workers; + found = results.find(Boolean) ?? null; + if (!found && Date.now() / 1000 - h.createdAt > 600) break; // stale template + } + if (!found) continue; + h.nonce = found.nonce; + const hash = sha256(miningBlob(h)); + const signature = Buffer.from(await subtle.sign({ name: 'ECDSA', hash: 'SHA-256' }, w.privateKey, + new TextEncoder().encode(blockClaimMessage(hash)))).toString('base64'); + const block: TestnetBlock = { ...h, hash, tokenId: mintId(h), powHash: found.hash, signature, transactions: template.transactions }; + blockSchema.parse(block); + try { + const res = await api(node, '/api/blocks', block); + if (!res.accepted) { console.error(`not accepted: ${JSON.stringify(res).slice(0, 200)}`); continue; } + accepted++; + const secs = (Date.now() - started) / 1000; + const line = `#${h.height} ${w.name} "${h.article.title}" token=${block.tokenId} via=${node} ${attempts}H ${(attempts / secs).toFixed(0)}H/s`; + console.log(`[${accepted}/${blocks}] ${line}`); + appendFileSync(`${STATE}/mined.log`, `${new Date().toISOString()} ${line}\n`); + } catch (e) { console.error(`submit: ${(e as Error).message}`); } + } +} finally { close(); } +console.log('done'); diff --git a/deploy/night/testnet.sh b/deploy/night/testnet.sh new file mode 100755 index 0000000..e392f4e --- /dev/null +++ b/deploy/night/testnet.sh @@ -0,0 +1,32 @@ +#!/bin/sh +# sim-testnet: private 3-node testnet fixture for WikiDeck Night 1 (poweredge-r350, LAN only). +# Usage (from the repo root): +# deploy/night/testnet.sh up build the image from this checkout and (re)start the 3 nodes +# deploy/night/testnet.sh mine N [W] mine N real RandomX blocks with W workers (default 4, max 8) +# deploy/night/testnet.sh status tip/height of each node +# deploy/night/testnet.sh down stop the nodes (volumes, i.e. the ledgers, are kept) +# STATE_DIR (default ~/.local/share/wikideck-night) holds the disposable testnet wallets and mined.log. +# It is outside the repo on purpose: never commit wallets. +set -eu +P=wikideck-night +LAN_IP=${LAN_IP:-192.168.1.32} +STATE_DIR=${STATE_DIR:-$HOME/.local/share/wikideck-night} +DC="docker compose -p $P -f compose.testnet.yaml -f deploy/night/compose.lan.yaml" +case "${1:-}" in + up) $DC build node-a && $DC up -d --no-build ;; + down) $DC down ;; + mine) + mkdir -p "$STATE_DIR" + W=${3:-4} + docker rm -f $P-miner >/dev/null 2>&1 || true + docker run -d --name $P-miner --network ${P}_default --cpus "$W" --memory 1600m \ + --user "$(id -u):$(id -g)" -e WIKIDECK_NETWORK=testnet -e WIKIDECK_GENESIS_TIME=1792411200 \ + -e MIN_GAP="${MIN_GAP:-45}" -v "$STATE_DIR":/state -v "$PWD/deploy/night":/night:ro \ + wikideck:testnet node --experimental-strip-types /night/mine.ts "$2" "$W" + echo "follow with: docker logs -f $P-miner" ;; + status) + for port in 3101 3102 3103; do + docker run --rm --network host wikideck:testnet node -e "fetch('http://$LAN_IP:$port/p2p/status').then(r=>r.json()).then(s=>console.log($port,'blocks',s.size,'tip',s.tip.slice(0,16))).catch(e=>console.log($port,'DOWN',e.message))" + done ;; + *) sed -n 2,9p "$0"; exit 1 ;; +esac From c1a13255644cbff35bb5be3e17f425950eba9c98 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 04:08:18 +0000 Subject: [PATCH 2/3] Night 1 handbook: avoid commands that trigger manual approval --- docs/night/HANDBOOK.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/night/HANDBOOK.md b/docs/night/HANDBOOK.md index 7d2bf85..2f55967 100644 --- a/docs/night/HANDBOOK.md +++ b/docs/night/HANDBOOK.md @@ -56,6 +56,7 @@ Turn WikiDeck into a game: flock /tmp/night-heavy.lock ``` - **imac** (8 threads, about 4 GB free) and **poweredge-r350** (16 threads, about 6 GB free): keep builds to one at a time. +- **Avoid permission prompts.** Nobody answers them, and they auto-deny after about a minute. Don't chain `cd && `; use absolute paths or `git -C ` instead. Keep each shell command to one clear purpose. - **LocalAI** (`https://localai.eom.dev`) is shared production with slow single-GPU inference. Don't use it in loops. ## Timeline (EST) From b2ec917af4719a3654c3fc72db929122b610c76f Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 17 Nov 2026 04:12:04 +0000 Subject: [PATCH 3/3] Night 1: DESIGN.md final v1 keyword set, 6 keywords with engine-b ids (#17) Co-Authored-By: Claude Opus 5.5 --- docs/game/DESIGN.md | 222 ++++++++++++++++++++++---------------------- 1 file changed, 109 insertions(+), 113 deletions(-) diff --git a/docs/game/DESIGN.md b/docs/game/DESIGN.md index 64104bc..11cd6ba 100644 --- a/docs/game/DESIGN.md +++ b/docs/game/DESIGN.md @@ -88,7 +88,7 @@ big cards are flexible. ### 1.5 Faction `faction` = the card's `category` (Space, Nature, People, Science, History, Culture), from `server/wiki.ts`. Culture is about half the pool, so faction keywords are written so that a -mono-faction deck gains no consistency edge (see §10, and `factionSynergyCap` in §9). +mono-faction deck gains no consistency edge (§10: no v1 keyword scales with faction count). ### 1.6 Trend (live, small, capped) `trend` = +1 if `live.trendPercent ≥ trendUp` (default 25), −1 if `≤ trendDown` (default −25), @@ -97,13 +97,11 @@ otherwise 0. A `null` value gives 0. Trend also needs `live.dailyAverage ≥ tre the match. It shows as an arrow (▲/▼), not a number. It adds to power in every Topic. ### 1.7 Rarity -The hash-derived `rarity` (`shared/protocol.ts:38`) sets the frame colour, and **it chooses the -keyword source, not power** (§10.1: a Common gets its home-stat keyword, a Rare or better gets its -faction keyword). Mining luck must not become power. +The hash-derived `rarity` (`shared/protocol.ts:38`) is **cosmetic in v1** (frame colour only). Mining luck must not +become power or keyword choice. ### 1.8 Keyword -Each card has at most **one** keyword, chosen deterministically from faction, home stat and rarity by -the table in §10 (owned by designer B). +Each card has at most **one** keyword: cost-1 cards are vanilla, and the others get their faction's keyword (§10.1). ### 1.9 Card face (phone) The card face shows **cost** (top-left), **power** (big, centre; the bonus shows as a "+N" badge on the home icon when the card is on-topic), a **home-stat icon** @@ -156,8 +154,7 @@ The engine does no I/O and only ever sees one version of each card. - 3 **Topics** (lanes), numbered 1–3 from left to right (top to bottom in portrait). - Each Topic has a **stat** (attention, depth or reach) and an optional **Portal** modifier (§10.3). - Topics have **no faction**. Faction matters only through keywords such as Rally, which count cards, - never Topics. + Topics have **no faction**. No v1 keyword counts factions: faction only picks the keyword. - Each player has at most `laneCapacity` cards per Topic (default **3**). That gives 9 slots per side, which caps cheap-card flooding and fits 3 cards across a 360 px phone. - **Topic pool:** `topicPool` is a list of Topics, each `{ id, name, stat, portal | null }`. The default @@ -268,7 +265,7 @@ the last turn's, and every "at scoring" Portal resolves **before** Topics are ju |---|---| | All-famous (all max-stat) deck | It becomes an all-cost-5/6 deck with dead early turns. Cheap cards are more efficient **per energy**, expensive cards **per card**. Only 9 cards are seen per match (3 + 6 draws), so both matter. The 1-energy carry-over lets a heavy deck bank energy for a turn-5 six-drop. **sim-balance target: heavy vs curve ≥ 40%.** | | All-cheap flood (cost 1–2) | Weak by design: only 9 slots and 9 cards seen. Critic's sim under these rules: swarm vs curve about 7–11%. Its home is Culture's wide-turn keyword (§10). | -| All one faction | Faction synergies are capped (`factionSynergyCap`), and Culture is the largest pool but has the weakest synergy keywords (§10). | +| All one faction | No v1 keyword scales with faction count. `factionSynergyCap` is reserved for modes. Culture, the largest pool, has the weakest keyword (viral). | | "Always play the highest-power card" | It ignores the on-topic bonus, lane capacity and the hidden Portals. Critic's sim: 18–21% against a smart bot (target < 55%). | | Stall or pass | Passing leaves lanes to any 1-power card. Two passing players draw. | | Mirror the AI | Hidden simultaneous commits: you only see the opponent's cards after you commit. | @@ -297,7 +294,7 @@ The engine takes a `RulesConfig` object. Peer-hosted modes override it (§11). D "costThresholds": [15, 35, 55, 75, 90], "powerByCost": [0, 1, 2, 4, 6, 8, 10], "onTopicBonus": [0, 1, 1, 2, 2, 3, 3], "vanillaBonus": 1, - "keywordsEnabled": ["Buzz","Anchor","Echo","Orbit","Grow","Rally","Research","Legacy","Remix"], "ownedCards": true, + "keywordsEnabled": ["viral","rising","local","encyclopedic","nostalgic","translated"], "ownedCards": true, "trendUp": 25, "trendDown": -25, "trendMinDaily": 20, "uncheckedCostCap": 4, "factionSynergyCap": 3, "verifyStats": true, @@ -317,76 +314,64 @@ A mode must keep `turns × turnSeconds ≤ 240` so that matches stay within 3– ## 10. Keywords *(owner: council-designer-b)* +**The v1 keyword set is these six, one per faction.** The ids are the ones engine-b already uses on `night/engine/keywords`. +Topics carry only a **stat**, never a faction. Every keyword below that mentions a Topic keys off stats or board state. + ### 10.1 Which keyword a card gets -The keyword comes from the card's **rarity**, **home stat** and **faction**, using the first rule that matches: +First rule that matches: +1. `cost == 1` → **no keyword** (vanilla). The card gets +`vanillaBonus` power (default **1**), so a cost-1 card is 2. +2. `"edition"` is in `keywordsEnabled` (off by default) and the deck holds another card with the same `pageId` → **edition**. +3. Otherwise → the card's **faction keyword** from 10.2, if it's in `keywordsEnabled`. If not, the card is vanilla, *without* `vanillaBonus`. -1. `cost == 1` → **no keyword**. Instead the card gets +`vanillaBonus` power (default **1**), so a cost-1 card has power 2. - Cheap cards stay simple, which helps new players. -2. `rarity == "Common"` → the **home-stat keyword** (Buzz, Anchor or Echo; table 10.2). -3. Otherwise (Rare, Epic or Legendary) → the **faction keyword** (table 10.2). +Rarity plays no part here (it's cosmetic, §1.7). Keywords don't lower power, and v1 has no per-keyword power deltas. +If sim shows that a keyword is worth more than about 1 power on average, sim-balance sets `keywordParams..powerDelta` (default 0, range −3 to 0). -This puts rarity to use, but only as *which* keyword a card has, never as how much power it has. Every keyword below is -worth about +1 to +3, which is the same as the trade-offs between home-stat keywords, so mining luck buys variety and not power. (This changes -§1.7 slightly. Designer-a, please note it there: "rarity chooses the keyword source, not power".) -Rough expected mix (with Common about 60%): about 15% vanilla, about 50% home-stat keywords, about 35% faction keywords. +### 10.2 Keyword list (v1) -Keywords are **one word** on the card face, plus one line of reminder text in the tap-to-inspect sheet. -They only ever *add* power (v1 has no removal, stealing, moving or lowering power). "Here" means this card's Topic, and -"your" means the owner's side. An effect stops at its cap, so no keyword moves a lane by more than 3 (§8 requires 6 or less). +| Faction | id (card word) | Trigger | Reminder text | Cap | Order-sensitive? | +|---|---|---|---|---|---| +| Culture | **viral** | On reveal | +1 power for each other card you revealed earlier this turn. | +2 | yes: your queue order | +| Nature | **rising** | End of turn | +1 power. | +2 total | no | +| People | **local** | Ongoing | +1 power while on-topic (the Topic's stat is its home stat). | +1 | no | +| Science | **encyclopedic** | On reveal | +2 power if there are no other cards here (either side). | +2 | **yes: interleaving** | +| History | **nostalgic** | On reveal | +2 power if you are losing here. | +2 | **yes: interleaving** | +| Space | **translated** | On reveal | +1 power to your most recently revealed card in each *other* Topic. | +2 | yes | -### 10.2 Keyword list - -| Keyword | Source | Trigger | Reminder text | Cap | -|---|---|---|---|---| -| **Buzz** | home: attention | On reveal | +1 power to each of your *other* cards here. | +2 (lane cap 3) | -| **Anchor** | home: depth | Ongoing | +2 power while it is your only card here. | +2 | -| **Echo** | home: reach | On reveal | +1 power to your most recently played card in each *other* Topic. | +2 (2 cards) | -| **Orbit** | faction: Space | Ongoing | +1 to your Topic power in each *adjacent* Topic. | +1 per adjacent Topic | -| **Grow** | faction: Nature | End of turn | +1 power. | +3 total | -| **Rally** | faction: People | On reveal | +1 power to each of your *other People* cards, in any Topic. | `factionSynergyCap` (3) | -| **Research** | faction: Science | On reveal | +1 power for each Topic you lead right now. | +3 | -| **Legacy** | faction: History | Ongoing | On the last turn, +2 power if this card has been here since turn 4 or earlier. | +2 | -| **Remix** | faction: Culture | On reveal | +2 power if you are losing here. | +2 | +Why this set: every keyword is one line and one trigger, and only adds power. The largest swing is +2 on one card, +so no lane moves by more than 2 from a keyword. Nothing scales with faction count, so a mono-Culture deck gets no +consistency edge (`factionSynergyCap` is unused in v1). Viral is Culture's weakest keyword, and it rewards wide turns. +Three keywords (encyclopedic, nostalgic, translated) react to the interleaved reveal (§5.4), so initiative and queue order matter. Precise rules (for engine-b): -- **On reveal** resolves when this card enters its Topic during Reveal (§5.4). It sees every card already revealed, - including cards the initiative player revealed earlier in the same turn. Bonuses it grants are permanent power counters on the target cards. -- **Ongoing** is recalculated every time Topic power is read. It's a condition, not a counter. -- **End of turn** resolves in §5.5 order: the initiative player's cards first, then Topic 1→3, then play order. -- **Buzz** targets only cards already here when it reveals. Cards that arrive later don't get the bonus. -- **Anchor** counts only its owner's cards here. Opposing cards don't matter. -- **Echo:** "most recently played" means the highest play sequence number among your cards in that Topic. Topics where you have no card are skipped. -- **Orbit** adds to Topic power, not to a card. It works even if you have no cards in the adjacent Topic (so Topic power can go 0 → 1). - Topic 2 is adjacent to 1 and 3. Topics 1 and 3 are adjacent only to 2. -- **Grow** stops after it has gained +3 in total. -- **Rally** counts cards by faction. Wildcard-style faction changes don't exist in v1. It gives at most `factionSynergyCap` counters in total, - going to the targets in play order. -- **Research** counts Topics where you lead (strictly greater Topic power) at the moment it resolves, including this - Topic after its own base and on-topic power is added. *(Clarification: the card's own power counts toward leading here.)* -- **Legacy** applies when `turn == turns` (the last turn), from the start of that turn, and only if the card was revealed on a turn ≤ `keywordParams.Legacy.byTurn` (default **4**, i.e. `turns − 2`). So committing a History card early is a real choice: it shows your hand to win the +2. -- **End-of-turn effects on the last turn resolve before scoring** (§7), so Grow's last +1 counts. -- **Remix:** "losing here" means the opponent's Topic power here is strictly greater than yours, counted just *before* this card - is added. -- **Culture is about half the pool,** so its faction keyword (Remix) is the one with no faction synergy. A Culture-heavy deck - gets no consistency bonus from being mono-faction. Only People (Rally) has faction synergy, and it's capped. +- **On reveal** resolves the moment the card enters its Topic, and sees every card revealed before it (both players, + including earlier reveals this turn). The bonuses it grants are permanent counters. +- **Ongoing** is a condition, recalculated whenever power is read. +- **End of turn** resolves in §5.5 order: the initiative player's cards first, then Topic 1→3, then reveal order. +- **viral:** counts the owner's cards revealed earlier in *this* turn's Reveal phase, in any Topic. Cards that went back to hand don't count. +- **rising:** stops after it has gained +2 in total. +- **local:** "on-topic" is exactly the §1.4/§6 condition. It's simply an extra +1 on top of `onTopicBonus`. +- **encyclopedic:** "no other cards here" means both sides of this Topic are empty, apart from this card, when it reveals. +- **nostalgic:** "losing here" means the opponent's Topic power here is strictly greater than yours, counted just *before* this card is added. + The consensus tie-break doesn't count: a tie is not losing. +- **translated:** "most recently revealed" means the highest global reveal sequence number among your cards in that Topic. Topics where you have no card are skipped. +- No v1 keyword uses the RNG. §4's "later random events" slot stays empty in v1. -Examples: -- *Buzz:* you have Haiku (2) and Jazz (4) in Topic 2, then play Pop music (Buzz, power 5). Haiku becomes 3, Jazz 5, and Pop music stays 5. -- *Anchor:* Coral reef (power 2) alone in Topic 1 is 4. Once you add another card there, it's 2 again. -- *Echo:* Moon is revealed in Topic 3. Your last card in Topic 1 gets +1. You have nothing in Topic 2, so that part is skipped. -- *Orbit:* Jupiter is in Topic 3, so your Topic 2 power is +1 even though no card there changed. -- *Rally:* Albert Einstein is revealed with no other People cards in play, so nothing happens. With Marie Curie and Ada Lovelace in play, each gets +1. -- *Research:* you lead Topics 1 and 3 when Periodic table is revealed into Topic 1, so it gets +2. -- *Legacy:* Ancient Rome (power 7) shows 7 on turns 5 and 9 on turn 6. -- *Remix:* the opponent has 6 here and you have 3, so Jazz (power 2) is revealed as 4. +**Already in code, disabled by default (`keywordsEnabled` excludes them; for modes only):** +- **edition:** +2 for each other copy of this `pageId` on your side. +- **obscure:** the opponent sees it face down until the end of the match. +- **wildcard:** its home stat becomes the Topic's stat on reveal. -**`keywordParams` defaults** (every number above, keyed by keyword id; modes may change them within 0–6): +These are engine-b's existing implementations. The faction-based versions of `local` and `wildcard`, and the token version of `viral`, are +**replaced** by the definitions above. + +**`keywordParams` defaults** (keyed by keyword id; modes may change them within the §11 ranges): ```json -{ "Buzz": {"amount": 1, "cap": 2}, "Anchor": {"amount": 2}, "Echo": {"amount": 1}, - "Orbit": {"amount": 1}, "Grow": {"amount": 1, "cap": 3}, "Rally": {"amount": 1, "cap": 3}, - "Research": {"amount": 1, "cap": 3}, "Legacy": {"amount": 2, "byTurn": 4}, "Remix": {"amount": 2} } +{ "viral": {"amount": 1, "cap": 2, "powerDelta": 0}, "rising": {"amount": 1, "cap": 2, "powerDelta": 0}, + "local": {"amount": 1, "powerDelta": 0}, "encyclopedic": {"amount": 2, "powerDelta": 0}, + "nostalgic": {"amount": 2, "powerDelta": 0}, "translated": {"amount": 1, "powerDelta": 0}, + "edition": {"amount": 2, "powerDelta": 0}, "obscure": {"powerDelta": 0}, "wildcard": {"powerDelta": 0} } ``` -Rally's cap is `factionSynergyCap` when that key is set. Otherwise it's `keywordParams.Rally.cap`. +End-of-turn effects on the last turn resolve **before** scoring (§7). ### 10.3 Portals (Topic modifiers) and the default Topic pool Each Topic has `{ id, name, stat, portal | null }`. The default `topicPool` has 9 Topics, one plain and two with @@ -412,7 +397,6 @@ As data: `portal = { kind: "scoringCardBonus", amount: 1 } | { kind: "trendMulti "featured-article": {"amount": 2}, "stub": {"value": 2}, "interwiki": {"amount": 1} }`. Disambiguation has no numbers. Topic ids are the names in kebab-case: `current-events, main-page, trending, archive, featured-article, stub, translations, interwiki, disambiguation`. The UI shows each Portal's one-line rule **on the lane itself**, not behind a tap. -Orbit's bonus is not on any card, so the UI shows it as a lane badge ("+1 🪐") next to the Topic total. --- @@ -447,8 +431,8 @@ A **mode** is data, published by a node operator and run by the match host: | `onTopicBonus` (7 entries), `vanillaBonus` | 0–5 each | | `trendUp` / `trendDown` | 0–200 / −200–0 | | `factionSynergyCap` | 0–6 | -| `keywordsEnabled` | any subset of the 9 v1 keywords; a disabled keyword makes those cards vanilla, *without* `vanillaBonus` | -| `keywordParams`, `portalParams` | only the keys listed in §10.2 / §10.3, each in 0–6 (`Legacy.byTurn` in 1..`turns`) | +| `keywordsEnabled` | any subset of the 9 implemented ids (the 6 v1 defaults + edition, obscure, wildcard); a card whose keyword is disabled is vanilla, *without* `vanillaBonus` | +| `keywordParams`, `portalParams` | only the keys listed in §10 / §10.3; amounts and caps 0–6, `powerDelta` −3–0 | | `verifyStats` | the host may only turn this off for modes that use only loaners (`maxLoaners == deckSize` and owned cards banned) | | `topicPool` | 3–20 Topics, Portal kinds only from 10.3 | @@ -471,52 +455,64 @@ Example modes (good defaults for operators to publish): ## 12. Worked example match *(owner: council-designer-b)* -This example uses the §1–11 rules of this PR. It was recomputed by council-critic (who checked it with a script) and re-checked by hand by designer-b. -- **Rules:** `powerByCost [0,1,2,4,6,8,10]`, `onTopicBonus [0,1,1,2,2,3,3]`, `vanillaBonus 1`, `laneCapacity 3`, - interleaved reveals, `underdog false`, no trend arrows. Nobody carries energy: both players spend 1/2/3/4/5/6. -- **Initiative:** Ana (p0) on odd turns, Bo (p1) on even turns. -- **Topics:** **T1 Archive (depth, plain)**, **T2 Main Page (attention; Portal revealed turn 3; at scoring, +1 per card here)**, - **T3 Translations (reach, plain)**. +These are the §1–9 rules as of this PR: +- `powerByCost [0,1,2,4,6,8,10]`, `onTopicBonus [0,1,1,2,2,3,3]`, `vanillaBonus 1` +- `laneCapacity 3`, `energyCarryMax 1`, interleaved reveals, alternating initiative, `portalReveal [2,3,4]` +- `underdog false`, no trend arrows -The cards are the §1 output, given directly. "Base" is `powerByCost[cost]`, with +1 for cost-1 vanilla cards; "+on" is `onTopicBonus[cost]`. +The derived cards are given directly (the §1 output), so the test needs no percentile table. +Topics: **T1 Archive (depth, plain)**, **T2 Main Page (attention; Portal revealed turn 3; at scoring, each card here gets +1)**, +**T3 Translations (reach, plain; revealed turn 4)**. Ana (p0) has initiative on odd turns and Bo (p1) on even turns. -| Player | Card | Faction / rarity | Cost | Base (+on) | Home | Keyword | +| Player | Card | Faction | Cost | Base | Home | Keyword | |---|---|---|---|---|---|---| -| Ana | Octopus | Nature / Common | 1 | 2 (+1) | depth | – (vanilla) | -| Ana | Moon | Space / Common | 2 | 2 (+1) | reach | Echo | -| Ana | Periodic table | Science / Rare | 3 | 4 (+2) | depth | Research | -| Ana | Albert Einstein | People / Epic | 4 | 6 (+2) | attention | Rally | -| Ana | Ancient Rome | History / Rare | 5 | 8 (+3) | depth | Legacy | -| Ana | Library of Alexandria | History / Common | 4 | 6 (+2) | depth | Anchor | -| Ana | Coral reef | Nature / Common | 2 | 2 (+1) | depth | Anchor | -| Bo | Haiku | Culture / Common | 1 | 2 (+1) | attention | – (vanilla) | -| Bo | Jazz | Culture / Rare | 2 | 2 (+1) | attention | Remix | -| Bo | Fern | Nature / Rare | 3 | 4 (+2) | depth | Grow | -| Bo | Pop music | Culture / Common | 4 | 6 (+2) | attention | Buzz | -| Bo | Jupiter | Space / Epic | 5 | 8 (+3) | reach | Orbit | -| Bo | Saturn | Space / Legendary | 6 | 10 (+3) | reach | Orbit | +| Ana | Octopus | Nature | 1 | 2 | depth | – (vanilla) | +| Ana | Moon | Space | 2 | 2 | reach | translated | +| Ana | Coral reef | Nature | 2 | 2 | depth | rising | +| Ana | Albert Einstein | People | 4 | 6 | attention | local | +| Ana | Ancient Rome | History | 5 | 8 | depth | nostalgic | +| Ana | Library of Alexandria | History | 4 | 6 | depth | nostalgic | +| Ana | Periodic table | Science | 3 | 4 | depth | encyclopedic | +| Bo | Haiku | Culture | 1 | 2 | attention | – (vanilla) | +| Bo | Mars | Space | 2 | 2 | reach | translated | +| Bo | Jazz | Culture | 2 | 2 | attention | viral | +| Bo | Pop music | Culture | 4 | 6 | attention | viral | +| Bo | Jupiter | Space | 5 | 8 | reach | translated | +| Bo | Fern | Nature | 3 | 4 | depth | rising | +| Bo | Mona Lisa | Culture | 3 | 4 | attention | viral | -Topic power is written as **Ana–Bo** after the End phase. +Topic power is written as **Ana–Bo** after End of turn. Energy is "available / spent". -| Turn | Initiative | Reveals (interleaved order) and effects | T1 | T2 | T3 | -|---|---|---|---|---|---| -| 1 | Ana | Ana Octopus → T1: 2+1 = **3**. Bo Haiku → T1: **2** (off-topic) | 3–2 | 0–0 | 0–0 | -| 2 | Bo | Bo Jazz → T2: 2+1 = 3. Remix: not losing (0–0), so no bonus. Ana Moon → T3: 2+1 = 3. Echo: Octopus +1 → 4 | 4–2 | 0–3 | 3–0 | -| 3 | Ana | Main Page Portal revealed. Ana Periodic table → T1: 4+2 = 6. Research: Ana leads T1 (10–2) and T3 (3–0), so +2 → **8**. Bo Fern → T1: 4+2 = 6. End, Grow: Fern 7 | 12–9 | 0–3 | 3–0 | -| 4 | Bo | Bo Pop music → T2: 6+2 = 8. Buzz: Jazz +1 → 4. Ana Einstein → T2: 6+2 = 8. Rally: no other People cards. End, Grow: Fern 8 | 12–10 | 8–12 | 3–0 | -| 5 | Ana | Ana Ancient Rome → T3: 8 (depth ≠ reach). Its Legacy can't apply, because it arrived on turn 5 > 4. Bo Jupiter → T3: 8+3 = 11. Orbit: Bo's T2 +1. End, Grow: Fern 9 (the +3 cap is reached) | 12–11 | 8–13 | 11–11 | -| 6 (last) | Bo | Bo Saturn → T3: 10+3 = 13. Orbit: Bo's T2 +1. Ana Library → T3: 6 (off-topic; Anchor no, not alone). Ana Coral reef → T1: 2+1 = 3 (Anchor no). Scoring: Main Page gives +1 per card in T2 | **15–11** | **9–16** | **17–24** | +| Turn | Init | Energy Ana / Bo | Reveals, in interleaved order | T1 | T2 | T3 | +|---|---|---|---|---|---|---| +| 1 | Ana | 1/1, 1/1 | Ana Octopus → T1: 2 +1 on-topic = **3**. Bo Haiku → T2: 2+1 = **3** | 3–0 | 0–3 | 0–0 | +| 2 | Bo | 2/2, 2/0 | Bo passes (to carry 1). Ana Moon → T3: 2+1 = 3. translated: Octopus +1 → 4 | 4–0 | 0–3 | 3–0 | +| 3 | Ana | 3/2, **4**/4 | Main Page Portal revealed. Ana Coral reef → T1: 2+1 = 3. Bo Mars → T3: 2+1 = 3, translated: Haiku +1 → 4. Bo Jazz → T2: 2+1 = 3, viral (Mars earlier) +1 → 4. End: rising Coral reef → 4 | 8–0 | 0–8 | 3–3 (tie; on-topic 1–1, so no leader) | +| 4 | Bo | **5**/4, 4/4 | Bo Pop music → T3: 6 (off-topic), viral +0. Ana Einstein → T2: 6+2 on-topic, local +1 = **9**. End: rising Coral reef → 5 (cap reached) | 9–0 | 9–8 | 3–9 | +| 5 | Ana | **6**/5, 5/5 | Ana Ancient Rome → T3: 8 (off-topic). nostalgic: losing 3–9, so +2 → **10**. Bo Jupiter → T1: 8 (off-topic). translated: Jazz → 5 (T2), Pop music → 7 (T3) | 9–8 | 9–9: **Bo leads** (consensus: on-topic 1 vs 2) | 13–10 | +| 6 (last) | Bo | **7**/7, 6/6 | Bo Fern → T1: 4+2 = 6. Ana Library → T1: 6+2 = 8. nostalgic: losing 9–14, so +2 → **10**. Bo Mona Lisa → T2: 4+2 = 6, viral (Fern earlier) +1 → 7. Ana Periodic table → T2: 4 (off-topic), encyclopedic: no (cards here). End: rising Fern → 7. Scoring: Main Page +1 per card in T2 | **19–15** | **15–19** | **13–10** | -Final board: -- **T1:** Ana has Octopus 4 + Periodic table 8 + Coral reef 3 = **15**. Bo has Haiku 2 + Fern 9 = **11**. → Ana -- **T2:** Ana has Einstein 8+1 = **9**. Bo has Jazz 4+1 + Pop music 8+1 + Orbit ×2 = **16**. → Bo -- **T3:** Ana has Moon 3 + Ancient Rome 8 + Library 6 = **17**. Bo has Jupiter 11 + Saturn 13 = **24**. → Bo +Final card values: +- **T1:** + - Ana: Octopus 4 + Coral reef 5 + Library 10 = 19. + - Bo: Jupiter 8 + Fern 7 = 15. +- **T2:** each card +1 from Main Page. + - Ana: Einstein 10 + Periodic table 5 = 15. + - Bo: Haiku 5 + Jazz 6 + Mona Lisa 8 = 19. +- **T3:** + - Ana: Moon 3 + Ancient Rome 10 = 13. + - Bo: Mars 3 + Pop music 7 = 10. -**Bo wins 2–1** (total power 41–51; the tie-break isn't needed). -The deciding moment was Ana's turn-5 Rome. It was off-topic in T3, and too late for Legacy. Saturn on-topic plus a second Orbit then took both T2 and T3. +**Ana wins 2–1.** Three moments show the v1 mechanics: +- **Carry-over:** Bo passed on turn 2 to afford two plays on turn 3 (4 energy). +- **Consensus:** T2 at 9–9 after turn 5 went to Bo, who had two on-topic attention cards to Ana's one. +- **Interleaving decides the match:** on turn 6 Bo had initiative, so Fern revealed before Library. Ana was then losing T1 (9 vs 14) and nostalgic fired (+2). + If Ana had revealed first, she'd have been ahead 9–8, nostalgic would not have fired, and T1 would have been 17–15. Ana still wins that lane, but by 2 instead of 4. -**Golden test (engine-b):** -- **Inject:** the Topic order, these 13 cards and these commit lists, in the queue order shown. -- **Expected final Topic powers:** `[[15,11],[9,16],[17,24]]` (Ana–Bo). Winner: p1. -- **Coverage:** vanilla, Echo, Research, Grow (including its cap), Buzz, Orbit ×2, the Main Page Portal at scoring, and Remix, Rally, Anchor and Legacy correctly **not** firing. -- **Separate unit tests:** add cases where Remix, Rally, Anchor and Legacy (here since turn ≤ 4) **do** fire. +**Golden test for engine-b:** +- **Inject:** the Topic order, the opening hands and the draw order directly, with each player's commit list per turn as in the table. The queue order within a turn is as listed. +- **Expected final Topic powers:** `T1 19–15, T2 15–19, T3 13–10`. Winner: p0, by 2 Topics to 1. +- **Also assert:** + - after turn 5, T2 is a 9–9 tie with Bo leading by consensus + - Ana's carried energy is 1 at the start of turns 4, 5 and 6 + - Bo's carried energy is 1 at the start of turn 3