Codemojex · chapter C4
Scoring and settlement — linear only.
Distance is the absolute gap between a guessed position and the secret’s; each position earns 100 − 20·d, and the six positions sum to a total out of 600. No tiers, no bonus — the leaderboard ranks the raw best total. Scoring is a pure fold; settlement is a guarded fan-out — a strategy the game selects, closing exactly once behind one SET NX lock.
Grounding — echo/apps/codemojex/lib/codemojex: scoring.ex · economy.ex (top_k_split) · board.ex · game.ex (ScoreWorker, Settle) · rooms.ex · sweep.ex · design §Core flows / §The game as a state machine.
Scoring.score/2 is pure. Each guessed emoji that exists in the secret earns 100 − 20·d for its distance d, zero for a miss — 100, 80, 60, 40, 20, 0 across distances 0..5. No process, no bus, no state.Two moves, one chapter
the shape of the workScoring is a pure fold. Codemojex.Scoring.score/2 maps a secret and a guess to a per-position breakdown and a total — no process, no bus, no state. The same secret and guess always yield the same number, which is exactly what makes at-least-once delivery harmless: a re-delivered guess re-scores identically. The distance math is one code path shared by every game type; the type branches feedback and settlement, never the arithmetic.
Settlement is a guarded fan-out. Closing a game takes an atomic SET cm:<game>:closed NX; only the caller that wins the lock runs the payout, and it runs one of three strategies chosen by the game’s snapshotted settlement policy — close_live (winner-take-all), close_sealed (reveal and top-K), or close_split (the Golden Room’s live top-K). Purity plus a one-shot lock stand in for a distributed transaction: a racing close, or a re-run, pays identically.
The reconcile: an earlier draft of this chapter described thirty tiers over twenty-point gaps — the first-mover bonus mechanic the engine removed. The design is now linear end to end: “there is no tier ladder and no first-mover bonus; the raw best total is the rank.”
The three dives
hub + 3 divesDistance and points
The per-position law 100 − 20·d: 100, 80, 60, 40, 20, 0 by distance, zero for a miss; the status words; scoring as a pure function.
The total out of 600
Six positions summed to the guess total; Board.record/3 folds the best into the base hash and the board ZSET; a perfect 600 closes a classic game.
Settlement strategies
The close race resolved exactly once by SET NX; live winner-take-all, sealed top-K, the Golden Room split; the never-fills void; the sweep.
Grounding — read on the running code: Codemojex.Scoring (scoring.ex), Codemojex.Board (board.ex), Codemojex.Economy (economy.ex), Codemojex.ScoreWorker / Codemojex.Settle (game.ex), Codemojex.Rooms (rooms.ex), Codemojex.Sweep (sweep.ex), and the scoring · settlement · golden-blind · golden-tournament stories.
References
sources · relatedSources
- Mastermind — the board gamethe guess-against-a-hidden-code loop the distance score sits in
- The feedback function and minimax code-breakingthe deductive structure the linear distance scoring approximates
Related
- Redis Patterns Applied
SET NXlocks and ZSET boards, applied - C3 — Guesses on Fair Laneshow a guess reaches the scorer
- C5 — The Economy and the Bankwhere the settled diamonds move