Files
scrabble-game/loadtest/internal/edge/ops.go
T
Ilia Denisov 92f48a3b12
CI / changes (pull_request) Successful in 1s
CI / unit (pull_request) Successful in 9s
CI / integration (pull_request) Successful in 12s
CI / ui (pull_request) Successful in 44s
CI / gate (pull_request) Successful in 0s
CI / deploy (pull_request) Successful in 1m9s
Backend infers play direction; UI previews words and gates submit on legality
A single tile that only extended a word perpendicular to the client-declared
direction was rejected: the UI always sent dir=H for one-tile plays (the
dirOverride/Controls toggle was orphaned in the Stage 7 game rework), so placing
"А" above "БАК" to form "АБАК" failed the solver's main-word-length check even
though the word is in the dictionary.

Make the backend infer a play's orientation from the placed tiles and the board
(internal/engine.resolveDirection): two or more tiles by the line they share, a
lone tile by the axis it abuts (longer word wins, horizontal on a tie). Direction
becomes an output, not an input: drop dir from the SubmitPlay/Eval wire requests
and add it to EvalResult. Journal replay keeps trusting the stored "H"/"V"
(SubmitPlayDir) so a rebuilt game matches the one committed.

UI: stop computing/sending direction; the preview now shows the words a move
forms with its total score (game.previewWords); the make-move control is disabled
until the play is confirmed legal; the "your turn" label hides while tiles are
pending. Delete the orphaned Controls.svelte.

Regenerate the FlatBuffers bindings (Go + TS) and update the gateway transcode
and the loadtest edge client to the new contract. Bake the decision into
ARCHITECTURE.md (§5/§9.1), FUNCTIONAL.md (+ _ru) and the backend README.
2026-06-11 22:42:33 +02:00

137 lines
5.4 KiB
Go

package edge
import "context"
// The typed operations below each build a request, run Execute and decode the
// response. They return the decoded value (where any), the domain result code
// ("ok" or a stable error code) and a transport error. The scenario layer times the
// call and records the code; a non-"ok" code with a nil error is a domain rejection
// (for example "not_your_turn"), not a failure of the harness.
// State fetches the caller's private view of a game.
func (c *Client) State(ctx context.Context, token, gameID string) (State, string, error) {
r, err := c.execute(ctx, token, msgState, stateReq(gameID, false))
if err != nil || r.Code != "ok" {
return State{}, r.Code, err
}
return decodeState(r.Payload), r.Code, nil
}
// History fetches a game's decoded move journal (the board-replay source).
func (c *Client) History(ctx context.Context, token, gameID string) ([]Move, string, error) {
r, err := c.execute(ctx, token, msgHistory, gameAction(gameID))
if err != nil || r.Code != "ok" {
return nil, r.Code, err
}
return decodeHistory(r.Payload), r.Code, nil
}
// SubmitPlay commits a play and returns the post-move game.
func (c *Client) SubmitPlay(ctx context.Context, token, gameID string, tiles []PlayTile) (Game, string, error) {
r, err := c.execute(ctx, token, msgSubmitPlay, submitPlay(gameID, tiles))
if err != nil || r.Code != "ok" {
return Game{}, r.Code, err
}
return decodeMoveResultGame(r.Payload), r.Code, nil
}
// Pass forfeits the turn and returns the post-move game.
func (c *Client) Pass(ctx context.Context, token, gameID string) (Game, string, error) {
r, err := c.execute(ctx, token, msgPass, gameAction(gameID))
if err != nil || r.Code != "ok" {
return Game{}, r.Code, err
}
return decodeMoveResultGame(r.Payload), r.Code, nil
}
// Exchange swaps the listed rack tiles and returns the post-move game.
func (c *Client) Exchange(ctx context.Context, token, gameID string, tiles []byte) (Game, string, error) {
r, err := c.execute(ctx, token, msgExchange, exchange(gameID, tiles))
if err != nil || r.Code != "ok" {
return Game{}, r.Code, err
}
return decodeMoveResultGame(r.Payload), r.Code, nil
}
// Nudge prods the opponent whose turn it is.
func (c *Client) Nudge(ctx context.Context, token, gameID string) (string, error) {
r, err := c.execute(ctx, token, msgNudge, gameAction(gameID))
return r.Code, err
}
// ChatPost posts a per-game chat line.
func (c *Client) ChatPost(ctx context.Context, token, gameID, body string) (string, error) {
r, err := c.execute(ctx, token, msgChatPost, chatPost(gameID, body))
return r.Code, err
}
// CheckWord looks a word up in the game's pinned dictionary.
func (c *Client) CheckWord(ctx context.Context, token, gameID string, word []byte) (string, error) {
r, err := c.execute(ctx, token, msgCheckWord, checkWord(gameID, word))
return r.Code, err
}
// DraftSave stores the player's client-side composition.
func (c *Client) DraftSave(ctx context.Context, token, gameID, jsonStr string) (string, error) {
r, err := c.execute(ctx, token, msgDraftSave, draftSave(gameID, jsonStr))
return r.Code, err
}
// DraftGet retrieves the player's stored composition.
func (c *Client) DraftGet(ctx context.Context, token, gameID string) (string, error) {
r, err := c.execute(ctx, token, msgDraftGet, gameAction(gameID))
return r.Code, err
}
// ProfileUpdate overwrites the profile, resending the marker display name.
func (c *Client) ProfileUpdate(ctx context.Context, token, displayName, lang string) (string, error) {
r, err := c.execute(ctx, token, msgProfileUpd, updateProfile(displayName, lang))
return r.Code, err
}
// Stats reads the caller's lifetime statistics.
func (c *Client) Stats(ctx context.Context, token string) (string, error) {
r, err := c.execute(ctx, token, msgStatsGet, nil)
return r.Code, err
}
// GamesList lists the caller's games (active and finished).
func (c *Client) GamesList(ctx context.Context, token string) ([]Game, string, error) {
r, err := c.execute(ctx, token, msgGamesList, nil)
if err != nil || r.Code != "ok" {
return nil, r.Code, err
}
return decodeGameList(r.Payload), r.Code, nil
}
// CreateInvitation proposes a 2-4 player friend game to the named invitees.
func (c *Client) CreateInvitation(ctx context.Context, token string, inviteeIDs []string, variant string) (string, error) {
r, err := c.execute(ctx, token, msgInvCreate, createInvitation(inviteeIDs, variant, 0))
return r.Code, err
}
// AcceptInvitation accepts an invitation by id (the completing accept starts the game).
func (c *Client) AcceptInvitation(ctx context.Context, token, invitationID string) (string, error) {
r, err := c.execute(ctx, token, msgInvAccept, invitationAction(invitationID))
return r.Code, err
}
// ListInvitations lists the caller's open invitations.
func (c *Client) ListInvitations(ctx context.Context, token string) ([]Invitation, string, error) {
r, err := c.execute(ctx, token, msgInvList, nil)
if err != nil || r.Code != "ok" {
return nil, r.Code, err
}
return decodeInvitationList(r.Payload), r.Code, nil
}
// Enqueue joins the per-variant auto-match pool and reports any immediate pairing.
func (c *Client) Enqueue(ctx context.Context, token, variant string) (bool, Game, string, error) {
r, err := c.execute(ctx, token, msgEnqueue, enqueueReq(variant))
if err != nil || r.Code != "ok" {
return false, Game{}, r.Code, err
}
matched, game := decodeMatch(r.Payload)
return matched, game, r.Code, nil
}