refactor(game): extract turnFlow.ts (Phase 5 of #132) - #140
Merged
nodots merged 1 commit intoJul 15, 2026
Merged
Conversation
Move the turn-progression logic into src/Game/turnFlow.ts as free functions: roll, switchDice, move, moveAndFinalize, toMoved, executeAndRecalculate, checkAndCompleteTurn, confirmTurn, startMove, and getPlayersForColor (used by roll). The public Game.* statics now delegate via 'public static X = X' to the imported free functions, so external callers (ai/api/client) and their type signatures are unchanged. Internal cross-calls go module-local (Rule A): roll->getPlayersForColor, moveAndFinalize->move/checkAndCompleteTurn, executeAndRecalculate->move/checkAndCompleteTurn/confirmTurn, checkAndCompleteTurn->toMoved. The player accessors activePlayer/inactivePlayer and the robot helpers (handleRobotMovedState, executeRobotTurn) stay on the class; handleRobotMovedState still reaches confirmTurn through the facade. Byte-exact relocation (mechanical extraction script) preserves behavior; the test suite is identical before and after. Removed now-dead value imports (Dice, Play, MoveExecutionOptions) from index.ts. index.ts drops ~1500 lines (~2050 -> 586). Note: switchDice coverage (weak, ~#134) is left as a follow-up coverage pass; this phase is a behavior-preserving move. No behavior change. Core: 475 passed / 12 skipped, tsc -b clean. Refs #132
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.
Phase 5 of the Game/index.ts decomposition epic (#133) — the big one
Stacked on #139 (Phase 4). Base is
refactor/game-decomp-phase4-lifecycle; retarget todevelopmentas parents merge.What changed
src/Game/turnFlow.tsholds the turn-progression logic as free functions:roll,switchDice,move,moveAndFinalize,toMoved,executeAndRecalculate,checkAndCompleteTurn,confirmTurn,startMove, andgetPlayersForColor(used byroll).Game.*statics now delegate viapublic static X = Xto the imported free functions — external ai/api/client callers and their type signatures are unchanged.roll→getPlayersForColor,moveAndFinalize→move/checkAndCompleteTurn,executeAndRecalculate→move/checkAndCompleteTurn/confirmTurn,checkAndCompleteTurn→toMoved.activePlayer/inactivePlayerand robot helpers (handleRobotMovedState,executeRobotTurn) stay on the class;handleRobotMovedStatereachesconfirmTurnthrough the facade.Dice,Play,MoveExecutionOptions) fromindex.ts.How
Byte-exact relocation via a mechanical extraction script (dedent,
public static X = function X→export function X,Game.Y(→Y(for internal callees only). No hand-transcription, so the code is character-identical to the original apart from those transforms.index.tsdrops ~1500 lines (~2050 → 586).Verification
tsc -b --forcecleannpx jest: 475 passed / 12 skipped — identical before and after (behavior-preserving move)Game.*API + signatures unchangedFollow-up
switchDicehas weak coverage (flagged in #134); left for a dedicated coverage pass since this phase is a pure move.Refs #132, #134