Stage 3: game domain (lifecycle, journal+cache, hint, word-check, GCG, stats)
internal/game drives the engine over a single match and owns everything the
engine does not: event-sourced persistence (a games row + an append-only decoded
move journal, with the live engine.Game kept warm in a cache and rebuilt by
replay on a miss), the play/pass/exchange/resign transitions with
validate-at-submit scoring, an unlimited score/legality preview, the hint
(per-game allowance + profile wallet), the word-check tool with complaint
capture, per-player game state, history and GCG export (Poslfit dialect), and a
background turn-timeout sweeper that auto-resigns overdue turns honouring each
player's daily away window. Like Stages 1-2 it is a service/store layer with no
HTTP; the gateway surface lands in Stage 6.
Engine: additive decoded domain API (Direction, SubmitPlay/SubmitExchange/
EvaluatePlay/HintView/Hand, MoveRecord.{Dir,MainRow,MainCol}, Registry.Lookup,
ParseVariant) so internal/game never imports scrabble-solver; and a Resign fix
so the resigner keeps their score yet never wins (the other player wins a
two-player game). Timeout reuses Resign.
Persistence: migration 00002 adds games, game_players, game_moves, complaints,
account_stats and extends accounts with away_start/away_end/hint_balance; go-jet
regenerated. account gained SpendHint. Config adds BACKEND_DICT_DIR (required),
BACKEND_DICT_VERSION, BACKEND_GAME_TIMEOUT_SWEEP_INTERVAL, BACKEND_GAME_CACHE_TTL;
main loads the registry at boot (hard dependency) and starts the sweeper.
Tests: engine resign + decoded-API tests; game unit tests (GCG, away-window
boundaries, hint budget, cache, keyed mutex, payload); inttest integration
(lifecycle, replay equivalence, timeout sweep with away grace, resign stats,
hint policy, word-check/complaint, per-game-lock). Docs (PLAN, ARCHITECTURE,
FUNCTIONAL +_ru, TESTING, README) updated.
This commit is contained in:
@@ -58,18 +58,31 @@ type TileRecord struct {
|
||||
// carries only the action; an exchange carries the number of tiles swapped. The
|
||||
// game domain adds timestamps and persistence around these values.
|
||||
type MoveRecord struct {
|
||||
Player int
|
||||
Action ActionKind
|
||||
Tiles []TileRecord // ActionPlay only
|
||||
Words []string // ActionPlay only: the main word first, then cross words
|
||||
Count int // ActionExchange only: number of tiles swapped
|
||||
Score int // points scored this turn (0 for non-plays)
|
||||
Total int // the player's running total after this turn
|
||||
Player int
|
||||
Action ActionKind
|
||||
Dir Direction // ActionPlay only: orientation of the main word (H/V)
|
||||
MainRow, MainCol int // ActionPlay only: the main word's first-letter coordinate
|
||||
Tiles []TileRecord // ActionPlay only
|
||||
Words []string // ActionPlay only: the main word first, then cross words
|
||||
Count int // ActionExchange only: number of tiles swapped
|
||||
Score int // points scored this turn (0 for non-plays)
|
||||
Total int // the player's running total after this turn
|
||||
}
|
||||
|
||||
// recordPlay decodes a scored move into a dictionary-independent MoveRecord for
|
||||
// the given player.
|
||||
// recordPlay decodes a scored, committed move into a dictionary-independent
|
||||
// MoveRecord for the given player, stamping the player and their running total.
|
||||
func (g *Game) recordPlay(player int, m scrabble.Move) MoveRecord {
|
||||
rec := g.decodeMove(m)
|
||||
rec.Player = player
|
||||
rec.Total = g.scores[player]
|
||||
return rec
|
||||
}
|
||||
|
||||
// decodeMove decodes a scored move's placements and words into a
|
||||
// dictionary-independent MoveRecord, without the player or running total (which
|
||||
// only a committed play has). It backs both recordPlay and the non-committing
|
||||
// previews HintView and EvaluatePlay.
|
||||
func (g *Game) decodeMove(m scrabble.Move) MoveRecord {
|
||||
tiles := make([]TileRecord, len(m.Tiles))
|
||||
for i, p := range m.Tiles {
|
||||
tiles[i] = TileRecord{Row: p.Row, Col: p.Col, Letter: g.letter(p.Letter), Blank: p.Blank}
|
||||
@@ -80,12 +93,13 @@ func (g *Game) recordPlay(player int, m scrabble.Move) MoveRecord {
|
||||
words = append(words, g.word(cw))
|
||||
}
|
||||
return MoveRecord{
|
||||
Player: player,
|
||||
Action: ActionPlay,
|
||||
Tiles: tiles,
|
||||
Words: words,
|
||||
Score: m.Score,
|
||||
Total: g.scores[player],
|
||||
Action: ActionPlay,
|
||||
Dir: fromScrabbleDir(m.Dir),
|
||||
MainRow: m.Main.Row,
|
||||
MainCol: m.Main.Col,
|
||||
Tiles: tiles,
|
||||
Words: words,
|
||||
Score: m.Score,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user