Repository navigation
refactor(shared): extract DeterministicRNG/SplitMix64 → DeterminismKit, MonotonicClock → TimeKit (#446) - #451
Merged
Conversation
…t, MonotonicClock → TimeKit (#446) Hoist the cross-engine deterministic primitives duplicated between SudokuCoreKit and MinesweeperCoreKit into shared Foundation-light leaves, eliminating the drift. Moves: - DeterministicRNG protocol (+ nextInt rejection sampling + shuffleInPlace Fisher-Yates) and SplitMix64 → new leaf Packages/DeterminismKit. - MonotonicClock + LiveMonotonicClock → existing TimeKit leaf. Reconciled the Sudoku-vs-Minesweeper divergence to the Sudoku superset: - shuffleInPlace existed only in the Sudoku copy; kept it (MS never used it). - nextInt(upperBound:) existed in Sudoku + MS DeterministicRNG; identical body. - Core algorithm (SplitMix64.next, nextInt threshold, LiveMonotonicClock.now) is bit-identical to the Sudoku originals. The MS copies were lossy subsets, not variants. Wiring: both CoreKits add a DeterminismKit dependency (already had TimeKit). SudokuEngine re-exports DeterminismKit, GameState re-exports TimeKit, MinesweeperEngine re-exports DeterminismKit, MinesweeperGameState re-exports TimeKit — mirroring the existing UTCDay @_exported precedent so every call site keeps compiling unedited. Deleted the 6 duplicate source files. Determinism preserved: a new DeterminismKit test pins SplitMix64(seed:0) to the frozen Phase-0 reference vector; all existing determinism/seed/snapshot tests pass unchanged (SudokuCoreKit 131, MinesweeperCoreKit 81, SudokuKit 220, MinesweeperKit 127). No snapshot PNGs re-recorded. Project.swift needs no change — DeterminismKit is pulled transitively via the umbrella packages, same as TimeKit and the CoreKits. Audio asset consolidation is OUT of scope, deferred to #446 part-2. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Closed
4 tasks
This was referenced Jun 9, 2026
Closed
Closed
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Hoists the cross-engine deterministic primitives that were duplicated between
SudokuCoreKitandMinesweeperCoreKitinto shared Foundation-light leaf targets, eliminating the drift. The RNG drives puzzle/board generation, so the merged code is bit-identical to the Sudoku originals.Refs #446 (code primitives part; audio assets deferred — see below).
Moves
DeterministicRNGprotocol (+nextInt(upperBound:),shuffleInPlace)SudokuEngine,MinesweeperEngine(dupes)Packages/DeterminismKitSplitMix64SudokuEngine,MinesweeperEngine(dupes)Packages/DeterminismKitMonotonicClock+LiveMonotonicClockGameState,MinesweeperGameState(dupes)Packages/TimeKit6 duplicate source files deleted.
Divergence reconciled (Sudoku-vs-Minesweeper)
The pairs had diverged; the shared version is the Sudoku superset, with each MS copy being a lossy subset (not a behavioral variant):
shuffleInPlace— existed only in the SudokuSplitMix64.swift. Kept in the shared leaf. Minesweeper never referenced it (MS does its own inline Fisher–Yates inMinesweeperEngine.swift), so this is purely additive for MS.nextInt(upperBound:)— present in both copies (Sudoku'sSplitMix64.swiftextension, MS'sDeterministicRNG.swiftextension); identical body (same Lemire-style rejection threshold). Unified once.SplitMix64.next()— identical constants in both; the MS file just carried fewer doc comments.MonotonicClock/LiveMonotonicClock— byte-identical between the two copies (git detected the Sudoku move as a 73% rename into TimeKit).The extension helpers (
nextInt,shuffleInPlace) wereinternalin-module before; they are nowpublicbecause the call sites live in a different module post-move. This is a required visibility change for the cross-module hoist; it does not alter behavior.Re-export wiring (no call-site edits)
Mirroring the existing
UTCDay@_exported importprecedent so every consumer keeps compiling unedited:SudokuEngine@_exported import DeterminismKitGameState@_exported import TimeKitMinesweeperEngine@_exported import DeterminismKitMinesweeperGameState@_exported import TimeKitBoth CoreKits add a
DeterminismKitpath dependency (they already depended onTimeKit).Determinism preserved
DeterminismKitTestspinsSplitMix64(seed: 0)to the frozen Phase-0 reference vector (meetings/2026-05-17_phase0-gates.md §0.1), independently proving the hoisted leaf is bit-identical.All four
swift builds (TimeKit, DeterminismKit, SudokuCoreKit, MinesweeperCoreKit) succeed.Project.swift
No change needed —
DeterminismKitis pulled in transitively via the umbrella packages (SudokuKit/MinesweeperKit), exactly asTimeKitand the CoreKits already are. The umbrella package builds above confirm auto-discovery.Out of scope
Audio asset consolidation is deferred to #446 part-2 per the issue scope — this PR is code primitives only.
🤖 Generated with Claude Code