Stage 13: alphabet on the wire (UI alphabet-agnostic, TODO-4)
Tests · Go / test (push) Successful in 10s
Tests · Integration / integration (push) Successful in 12s
Tests · UI / test (push) Successful in 19s
Tests · Go / test (pull_request) Successful in 9s
Tests · Integration / integration (pull_request) Successful in 12s
Tests · UI / test (pull_request) Successful in 19s

Live play now exchanges per-variant alphabet indices instead of concrete
letters (rack out; submit-play, evaluate, exchange, word-check in). The client
caches each variant's (index, letter, value) table behind
StateRequest.include_alphabet and renders the rack and blank chooser from it,
dropping the hardcoded value/alphabet tables. History, the durable journal and
GCG stay decoded concrete characters (ARCHITECTURE §9.1, unchanged).

- pkg/fbs: new AlphabetEntry + PlayTile; StateView.rack -> [ubyte] + alphabet;
  StateRequest.include_alphabet; SubmitPlay/Eval tiles -> [PlayTile];
  Exchange tiles + CheckWord word -> [ubyte] (committed Go + TS regenerated).
- engine: AlphabetTable + a cached per-variant codec (LetterForIndex/EncodeRack/
  DecodeTiles/DecodeWord) + BlankIndex sentinel; Go parity test.
- backend server edge maps index<->letter (new thin game.Service.GameVariant);
  game.Service domain methods, engine.Game and the robot keep one letter-based
  play path. The gateway forwards indices verbatim (no alphabet table).
- ui: lib/alphabet.ts in-memory cache; codec encodes/decodes indices; premiums.ts
  is geometry-only; the mock seeds a fixture table; the UI normalises display to
  upper case (codec + cache), leaving placement/board/checkword unchanged.

Parity moved to the Go engine.AlphabetTable test; premiums.ts loses its value
tables. Discharges TODO-4.
This commit is contained in:
Ilia Denisov
2026-06-04 16:26:43 +02:00
parent 6537082397
commit 90eaf4964b
47 changed files with 1812 additions and 272 deletions
+41
View File
@@ -0,0 +1,41 @@
// Mock alphabet fixtures (Stage 13). In production the per-variant (index, letter, value)
// table comes from the server; the mock seeds the same client cache from a local copy so
// the rack, the blank chooser and the mock's scoring work with no backend. The data is the
// solver's value tables (scrabble-solver/rules/rules.go), in alphabet-index order, so a
// token's position is its index — the same shape the wire delivers.
import { setAlphabet, type AlphabetEntryWire } from '../alphabet';
import type { Variant } from '../model';
// "letter+value" tokens in alphabet-index order. English Latin a..z; Russian а..я incl. ё;
// Эрудит а..я incl. ё=0.
const SPECS: Record<Variant, string> = {
english:
'a1 b3 c3 d2 e1 f4 g2 h4 i1 j8 k5 l1 m3 n1 o1 p3 q10 r1 s1 t1 u1 v4 w4 x8 y4 z10',
russian:
'а1 б3 в1 г3 д2 е1 ё3 ж5 з5 и1 й4 к2 л2 м2 н1 о1 п2 р1 с1 т1 у2 ф10 х5 ц5 ч5 ш8 щ10 ъ10 ы4 ь3 э8 ю8 я3',
erudit:
'а1 б3 в2 г3 д2 е1 ё0 ж5 з5 и1 й2 к2 л2 м2 н1 о1 п2 р2 с2 т2 у3 ф10 х5 ц10 ч5 ш10 щ10 ъ10 ы5 ь5 э10 ю10 я3',
};
function parse(spec: string): AlphabetEntryWire[] {
return spec
.trim()
.split(/\s+/)
.map((tok, index) => {
const m = tok.match(/^(.+?)(\d+)$/);
return { index, letter: m ? m[1] : tok, value: m ? Number(m[2]) : 0 };
});
}
let seeded = false;
/** seedMockAlphabets populates the alphabet cache for every variant once, mirroring the
* server-sent tables so the mock-driven UI is alphabet-agnostic too. */
export function seedMockAlphabets(): void {
if (seeded) return;
for (const variant of Object.keys(SPECS) as Variant[]) {
setAlphabet(variant, parse(SPECS[variant]));
}
seeded = true;
}