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
+44 -14
View File
@@ -14,8 +14,9 @@ namespace scrabblefb;
// --- shared building blocks ---
// TileRecord is one placed (or to-place) tile: its board coordinate, the concrete
// letter ("?" when read from a hand for a blank) and whether it came from a blank.
// TileRecord is one tile in a decoded move record (history, move result, hint): its
// board coordinate, the concrete letter ("?" when read from a hand for a blank) and
// whether it came from a blank. Inbound tiles to place use PlayTile (alphabet indices).
table TileRecord {
row:int;
col:int;
@@ -23,6 +24,25 @@ table TileRecord {
blank:bool;
}
// PlayTile is one inbound tile to place, addressed by its alphabet index rather than a
// concrete letter (Stage 13). For a blank, letter carries the designated letter's index
// and blank is true. The board coordinate is its target square.
table PlayTile {
row:int;
col:int;
letter:ubyte;
blank:bool;
}
// AlphabetEntry is one letter of a variant's alphabet, sent for display only (Stage 13):
// index is the engine alphabet-index byte the wire uses for this letter, letter is the
// concrete character and value is its tile score. The client caches the table per variant.
table AlphabetEntry {
index:ubyte;
letter:string;
value:int;
}
// SeatView is one seat's public standing in a game. display_name is resolved by the
// backend from the account store (added trailing — backward-compatible).
table SeatView {
@@ -123,11 +143,12 @@ table Profile {
// --- game (authenticated) ---
// SubmitPlayRequest places tiles in a direction on the player's turn.
// SubmitPlayRequest places tiles in a direction on the player's turn. tiles are addressed
// by alphabet index (Stage 13).
table SubmitPlayRequest {
game_id:string;
dir:string;
tiles:[TileRecord];
tiles:[PlayTile];
}
// MoveResult is the outcome of a committed move: the move and the post-move game.
@@ -136,19 +157,25 @@ table MoveResult {
game:GameView;
}
// StateRequest asks for the requesting player's view of a game.
// StateRequest asks for the requesting player's view of a game. include_alphabet asks the
// backend to embed the variant's AlphabetEntry table in the reply (Stage 13); the client
// sets it only on a per-variant cache miss so the table is not resent on every poll.
table StateRequest {
game_id:string;
include_alphabet:bool = false;
}
// StateView is a player's view of a game: the shared summary plus their private
// rack, the bag size and their remaining hint budget.
// StateView is a player's view of a game: the shared summary plus their private rack, the
// bag size and their remaining hint budget. rack carries alphabet indices (Stage 13); a
// blank tile is the sentinel index 255. alphabet is present only when the request set
// include_alphabet (a display table the client caches per variant).
table StateView {
game:GameView;
seat:int;
rack:[string];
rack:[ubyte];
bag_len:int;
hints_remaining:int;
alphabet:[AlphabetEntry];
}
// GameActionRequest carries just a game id (pass / resign / hint / history).
@@ -156,17 +183,19 @@ table GameActionRequest {
game_id:string;
}
// ExchangeRequest swaps the listed rack tiles back into the bag.
// ExchangeRequest swaps the listed rack tiles back into the bag. tiles are alphabet
// indices (Stage 13); a blank is the sentinel index 255.
table ExchangeRequest {
game_id:string;
tiles:[string];
tiles:[ubyte];
}
// EvalRequest previews a tentative play without committing it.
// EvalRequest previews a tentative play without committing it. tiles are addressed by
// alphabet index (Stage 13).
table EvalRequest {
game_id:string;
dir:string;
tiles:[TileRecord];
tiles:[PlayTile];
}
// EvalResult is an unlimited move preview: legality, score and the words formed.
@@ -176,10 +205,11 @@ table EvalResult {
words:[string];
}
// CheckWordRequest looks a word up in the game's pinned dictionary.
// CheckWordRequest looks a word up in the game's pinned dictionary. word is a sequence of
// alphabet indices (Stage 13); the client constrains input to the variant's alphabet.
table CheckWordRequest {
game_id:string;
word:string;
word:[ubyte];
}
// WordCheckResult is the dictionary lookup outcome.
+90
View File
@@ -0,0 +1,90 @@
// Code generated by the FlatBuffers compiler. DO NOT EDIT.
package scrabblefb
import (
flatbuffers "github.com/google/flatbuffers/go"
)
type AlphabetEntry struct {
_tab flatbuffers.Table
}
func GetRootAsAlphabetEntry(buf []byte, offset flatbuffers.UOffsetT) *AlphabetEntry {
n := flatbuffers.GetUOffsetT(buf[offset:])
x := &AlphabetEntry{}
x.Init(buf, n+offset)
return x
}
func FinishAlphabetEntryBuffer(builder *flatbuffers.Builder, offset flatbuffers.UOffsetT) {
builder.Finish(offset)
}
func GetSizePrefixedRootAsAlphabetEntry(buf []byte, offset flatbuffers.UOffsetT) *AlphabetEntry {
n := flatbuffers.GetUOffsetT(buf[offset+flatbuffers.SizeUint32:])
x := &AlphabetEntry{}
x.Init(buf, n+offset+flatbuffers.SizeUint32)
return x
}
func FinishSizePrefixedAlphabetEntryBuffer(builder *flatbuffers.Builder, offset flatbuffers.UOffsetT) {
builder.FinishSizePrefixed(offset)
}
func (rcv *AlphabetEntry) Init(buf []byte, i flatbuffers.UOffsetT) {
rcv._tab.Bytes = buf
rcv._tab.Pos = i
}
func (rcv *AlphabetEntry) Table() flatbuffers.Table {
return rcv._tab
}
func (rcv *AlphabetEntry) Index() byte {
o := flatbuffers.UOffsetT(rcv._tab.Offset(4))
if o != 0 {
return rcv._tab.GetByte(o + rcv._tab.Pos)
}
return 0
}
func (rcv *AlphabetEntry) MutateIndex(n byte) bool {
return rcv._tab.MutateByteSlot(4, n)
}
func (rcv *AlphabetEntry) Letter() []byte {
o := flatbuffers.UOffsetT(rcv._tab.Offset(6))
if o != 0 {
return rcv._tab.ByteVector(o + rcv._tab.Pos)
}
return nil
}
func (rcv *AlphabetEntry) Value() int32 {
o := flatbuffers.UOffsetT(rcv._tab.Offset(8))
if o != 0 {
return rcv._tab.GetInt32(o + rcv._tab.Pos)
}
return 0
}
func (rcv *AlphabetEntry) MutateValue(n int32) bool {
return rcv._tab.MutateInt32Slot(8, n)
}
func AlphabetEntryStart(builder *flatbuffers.Builder) {
builder.StartObject(3)
}
func AlphabetEntryAddIndex(builder *flatbuffers.Builder, index byte) {
builder.PrependByteSlot(0, index, 0)
}
func AlphabetEntryAddLetter(builder *flatbuffers.Builder, letter flatbuffers.UOffsetT) {
builder.PrependUOffsetTSlot(1, flatbuffers.UOffsetT(letter), 0)
}
func AlphabetEntryAddValue(builder *flatbuffers.Builder, value int32) {
builder.PrependInt32Slot(2, value, 0)
}
func AlphabetEntryEnd(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
return builder.EndObject()
}
+30 -1
View File
@@ -49,7 +49,24 @@ func (rcv *CheckWordRequest) GameId() []byte {
return nil
}
func (rcv *CheckWordRequest) Word() []byte {
func (rcv *CheckWordRequest) Word(j int) byte {
o := flatbuffers.UOffsetT(rcv._tab.Offset(6))
if o != 0 {
a := rcv._tab.Vector(o)
return rcv._tab.GetByte(a + flatbuffers.UOffsetT(j*1))
}
return 0
}
func (rcv *CheckWordRequest) WordLength() int {
o := flatbuffers.UOffsetT(rcv._tab.Offset(6))
if o != 0 {
return rcv._tab.VectorLen(o)
}
return 0
}
func (rcv *CheckWordRequest) WordBytes() []byte {
o := flatbuffers.UOffsetT(rcv._tab.Offset(6))
if o != 0 {
return rcv._tab.ByteVector(o + rcv._tab.Pos)
@@ -57,6 +74,15 @@ func (rcv *CheckWordRequest) Word() []byte {
return nil
}
func (rcv *CheckWordRequest) MutateWord(j int, n byte) bool {
o := flatbuffers.UOffsetT(rcv._tab.Offset(6))
if o != 0 {
a := rcv._tab.Vector(o)
return rcv._tab.MutateByte(a+flatbuffers.UOffsetT(j*1), n)
}
return false
}
func CheckWordRequestStart(builder *flatbuffers.Builder) {
builder.StartObject(2)
}
@@ -66,6 +92,9 @@ func CheckWordRequestAddGameId(builder *flatbuffers.Builder, gameId flatbuffers.
func CheckWordRequestAddWord(builder *flatbuffers.Builder, word flatbuffers.UOffsetT) {
builder.PrependUOffsetTSlot(1, flatbuffers.UOffsetT(word), 0)
}
func CheckWordRequestStartWordVector(builder *flatbuffers.Builder, numElems int) flatbuffers.UOffsetT {
return builder.StartVector(1, numElems, 1)
}
func CheckWordRequestEnd(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
return builder.EndObject()
}
+1 -1
View File
@@ -57,7 +57,7 @@ func (rcv *EvalRequest) Dir() []byte {
return nil
}
func (rcv *EvalRequest) Tiles(obj *TileRecord, j int) bool {
func (rcv *EvalRequest) Tiles(obj *PlayTile, j int) bool {
o := flatbuffers.UOffsetT(rcv._tab.Offset(8))
if o != 0 {
x := rcv._tab.Vector(o)
+21 -4
View File
@@ -49,13 +49,13 @@ func (rcv *ExchangeRequest) GameId() []byte {
return nil
}
func (rcv *ExchangeRequest) Tiles(j int) []byte {
func (rcv *ExchangeRequest) Tiles(j int) byte {
o := flatbuffers.UOffsetT(rcv._tab.Offset(6))
if o != 0 {
a := rcv._tab.Vector(o)
return rcv._tab.ByteVector(a + flatbuffers.UOffsetT(j*4))
return rcv._tab.GetByte(a + flatbuffers.UOffsetT(j*1))
}
return nil
return 0
}
func (rcv *ExchangeRequest) TilesLength() int {
@@ -66,6 +66,23 @@ func (rcv *ExchangeRequest) TilesLength() int {
return 0
}
func (rcv *ExchangeRequest) TilesBytes() []byte {
o := flatbuffers.UOffsetT(rcv._tab.Offset(6))
if o != 0 {
return rcv._tab.ByteVector(o + rcv._tab.Pos)
}
return nil
}
func (rcv *ExchangeRequest) MutateTiles(j int, n byte) bool {
o := flatbuffers.UOffsetT(rcv._tab.Offset(6))
if o != 0 {
a := rcv._tab.Vector(o)
return rcv._tab.MutateByte(a+flatbuffers.UOffsetT(j*1), n)
}
return false
}
func ExchangeRequestStart(builder *flatbuffers.Builder) {
builder.StartObject(2)
}
@@ -76,7 +93,7 @@ func ExchangeRequestAddTiles(builder *flatbuffers.Builder, tiles flatbuffers.UOf
builder.PrependUOffsetTSlot(1, flatbuffers.UOffsetT(tiles), 0)
}
func ExchangeRequestStartTilesVector(builder *flatbuffers.Builder, numElems int) flatbuffers.UOffsetT {
return builder.StartVector(4, numElems, 4)
return builder.StartVector(1, numElems, 1)
}
func ExchangeRequestEnd(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
return builder.EndObject()
+109
View File
@@ -0,0 +1,109 @@
// Code generated by the FlatBuffers compiler. DO NOT EDIT.
package scrabblefb
import (
flatbuffers "github.com/google/flatbuffers/go"
)
type PlayTile struct {
_tab flatbuffers.Table
}
func GetRootAsPlayTile(buf []byte, offset flatbuffers.UOffsetT) *PlayTile {
n := flatbuffers.GetUOffsetT(buf[offset:])
x := &PlayTile{}
x.Init(buf, n+offset)
return x
}
func FinishPlayTileBuffer(builder *flatbuffers.Builder, offset flatbuffers.UOffsetT) {
builder.Finish(offset)
}
func GetSizePrefixedRootAsPlayTile(buf []byte, offset flatbuffers.UOffsetT) *PlayTile {
n := flatbuffers.GetUOffsetT(buf[offset+flatbuffers.SizeUint32:])
x := &PlayTile{}
x.Init(buf, n+offset+flatbuffers.SizeUint32)
return x
}
func FinishSizePrefixedPlayTileBuffer(builder *flatbuffers.Builder, offset flatbuffers.UOffsetT) {
builder.FinishSizePrefixed(offset)
}
func (rcv *PlayTile) Init(buf []byte, i flatbuffers.UOffsetT) {
rcv._tab.Bytes = buf
rcv._tab.Pos = i
}
func (rcv *PlayTile) Table() flatbuffers.Table {
return rcv._tab
}
func (rcv *PlayTile) Row() int32 {
o := flatbuffers.UOffsetT(rcv._tab.Offset(4))
if o != 0 {
return rcv._tab.GetInt32(o + rcv._tab.Pos)
}
return 0
}
func (rcv *PlayTile) MutateRow(n int32) bool {
return rcv._tab.MutateInt32Slot(4, n)
}
func (rcv *PlayTile) Col() int32 {
o := flatbuffers.UOffsetT(rcv._tab.Offset(6))
if o != 0 {
return rcv._tab.GetInt32(o + rcv._tab.Pos)
}
return 0
}
func (rcv *PlayTile) MutateCol(n int32) bool {
return rcv._tab.MutateInt32Slot(6, n)
}
func (rcv *PlayTile) Letter() byte {
o := flatbuffers.UOffsetT(rcv._tab.Offset(8))
if o != 0 {
return rcv._tab.GetByte(o + rcv._tab.Pos)
}
return 0
}
func (rcv *PlayTile) MutateLetter(n byte) bool {
return rcv._tab.MutateByteSlot(8, n)
}
func (rcv *PlayTile) Blank() bool {
o := flatbuffers.UOffsetT(rcv._tab.Offset(10))
if o != 0 {
return rcv._tab.GetBool(o + rcv._tab.Pos)
}
return false
}
func (rcv *PlayTile) MutateBlank(n bool) bool {
return rcv._tab.MutateBoolSlot(10, n)
}
func PlayTileStart(builder *flatbuffers.Builder) {
builder.StartObject(4)
}
func PlayTileAddRow(builder *flatbuffers.Builder, row int32) {
builder.PrependInt32Slot(0, row, 0)
}
func PlayTileAddCol(builder *flatbuffers.Builder, col int32) {
builder.PrependInt32Slot(1, col, 0)
}
func PlayTileAddLetter(builder *flatbuffers.Builder, letter byte) {
builder.PrependByteSlot(2, letter, 0)
}
func PlayTileAddBlank(builder *flatbuffers.Builder, blank bool) {
builder.PrependBoolSlot(3, blank, false)
}
func PlayTileEnd(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
return builder.EndObject()
}
+16 -1
View File
@@ -49,12 +49,27 @@ func (rcv *StateRequest) GameId() []byte {
return nil
}
func (rcv *StateRequest) IncludeAlphabet() bool {
o := flatbuffers.UOffsetT(rcv._tab.Offset(6))
if o != 0 {
return rcv._tab.GetBool(o + rcv._tab.Pos)
}
return false
}
func (rcv *StateRequest) MutateIncludeAlphabet(n bool) bool {
return rcv._tab.MutateBoolSlot(6, n)
}
func StateRequestStart(builder *flatbuffers.Builder) {
builder.StartObject(1)
builder.StartObject(2)
}
func StateRequestAddGameId(builder *flatbuffers.Builder, gameId flatbuffers.UOffsetT) {
builder.PrependUOffsetTSlot(0, flatbuffers.UOffsetT(gameId), 0)
}
func StateRequestAddIncludeAlphabet(builder *flatbuffers.Builder, includeAlphabet bool) {
builder.PrependBoolSlot(1, includeAlphabet, false)
}
func StateRequestEnd(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
return builder.EndObject()
}
+48 -5
View File
@@ -66,13 +66,13 @@ func (rcv *StateView) MutateSeat(n int32) bool {
return rcv._tab.MutateInt32Slot(6, n)
}
func (rcv *StateView) Rack(j int) []byte {
func (rcv *StateView) Rack(j int) byte {
o := flatbuffers.UOffsetT(rcv._tab.Offset(8))
if o != 0 {
a := rcv._tab.Vector(o)
return rcv._tab.ByteVector(a + flatbuffers.UOffsetT(j*4))
return rcv._tab.GetByte(a + flatbuffers.UOffsetT(j*1))
}
return nil
return 0
}
func (rcv *StateView) RackLength() int {
@@ -83,6 +83,23 @@ func (rcv *StateView) RackLength() int {
return 0
}
func (rcv *StateView) RackBytes() []byte {
o := flatbuffers.UOffsetT(rcv._tab.Offset(8))
if o != 0 {
return rcv._tab.ByteVector(o + rcv._tab.Pos)
}
return nil
}
func (rcv *StateView) MutateRack(j int, n byte) bool {
o := flatbuffers.UOffsetT(rcv._tab.Offset(8))
if o != 0 {
a := rcv._tab.Vector(o)
return rcv._tab.MutateByte(a+flatbuffers.UOffsetT(j*1), n)
}
return false
}
func (rcv *StateView) BagLen() int32 {
o := flatbuffers.UOffsetT(rcv._tab.Offset(10))
if o != 0 {
@@ -107,8 +124,28 @@ func (rcv *StateView) MutateHintsRemaining(n int32) bool {
return rcv._tab.MutateInt32Slot(12, n)
}
func (rcv *StateView) Alphabet(obj *AlphabetEntry, j int) bool {
o := flatbuffers.UOffsetT(rcv._tab.Offset(14))
if o != 0 {
x := rcv._tab.Vector(o)
x += flatbuffers.UOffsetT(j) * 4
x = rcv._tab.Indirect(x)
obj.Init(rcv._tab.Bytes, x)
return true
}
return false
}
func (rcv *StateView) AlphabetLength() int {
o := flatbuffers.UOffsetT(rcv._tab.Offset(14))
if o != 0 {
return rcv._tab.VectorLen(o)
}
return 0
}
func StateViewStart(builder *flatbuffers.Builder) {
builder.StartObject(5)
builder.StartObject(6)
}
func StateViewAddGame(builder *flatbuffers.Builder, game flatbuffers.UOffsetT) {
builder.PrependUOffsetTSlot(0, flatbuffers.UOffsetT(game), 0)
@@ -120,7 +157,7 @@ func StateViewAddRack(builder *flatbuffers.Builder, rack flatbuffers.UOffsetT) {
builder.PrependUOffsetTSlot(2, flatbuffers.UOffsetT(rack), 0)
}
func StateViewStartRackVector(builder *flatbuffers.Builder, numElems int) flatbuffers.UOffsetT {
return builder.StartVector(4, numElems, 4)
return builder.StartVector(1, numElems, 1)
}
func StateViewAddBagLen(builder *flatbuffers.Builder, bagLen int32) {
builder.PrependInt32Slot(3, bagLen, 0)
@@ -128,6 +165,12 @@ func StateViewAddBagLen(builder *flatbuffers.Builder, bagLen int32) {
func StateViewAddHintsRemaining(builder *flatbuffers.Builder, hintsRemaining int32) {
builder.PrependInt32Slot(4, hintsRemaining, 0)
}
func StateViewAddAlphabet(builder *flatbuffers.Builder, alphabet flatbuffers.UOffsetT) {
builder.PrependUOffsetTSlot(5, flatbuffers.UOffsetT(alphabet), 0)
}
func StateViewStartAlphabetVector(builder *flatbuffers.Builder, numElems int) flatbuffers.UOffsetT {
return builder.StartVector(4, numElems, 4)
}
func StateViewEnd(builder *flatbuffers.Builder) flatbuffers.UOffsetT {
return builder.EndObject()
}
+1 -1
View File
@@ -57,7 +57,7 @@ func (rcv *SubmitPlayRequest) Dir() []byte {
return nil
}
func (rcv *SubmitPlayRequest) Tiles(obj *TileRecord, j int) bool {
func (rcv *SubmitPlayRequest) Tiles(obj *PlayTile, j int) bool {
o := flatbuffers.UOffsetT(rcv._tab.Offset(8))
if o != 0 {
x := rcv._tab.Vector(o)