Skip to content

refactor(game): extract turnFlow.ts (Phase 5 of #132) - #140

Merged
nodots merged 1 commit into
refactor/game-decomp-phase4-lifecyclefrom
refactor/game-decomp-phase5-turnflow
Jul 15, 2026
Merged

refactor(game): extract turnFlow.ts (Phase 5 of #132)#140
nodots merged 1 commit into
refactor/game-decomp-phase4-lifecyclefrom
refactor/game-decomp-phase5-turnflow

Conversation

@nodots

@nodots nodots commented Jul 15, 2026

Copy link
Copy Markdown
Owner

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 to development as parents merge.

What changed

  • New src/Game/turnFlow.ts holds the turn-progression logic 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 — external ai/api/client callers and their type signatures are unchanged.
  • Internal cross-calls are module-local (Rule A): rollgetPlayersForColor, moveAndFinalizemove/checkAndCompleteTurn, executeAndRecalculatemove/checkAndCompleteTurn/confirmTurn, checkAndCompleteTurntoMoved.
  • The player accessors activePlayer/inactivePlayer and robot helpers (handleRobotMovedState, executeRobotTurn) stay on the class; handleRobotMovedState reaches confirmTurn through the facade.
  • Removed now-dead value imports (Dice, Play, MoveExecutionOptions) from index.ts.

How

Byte-exact relocation via a mechanical extraction script (dedent, public static X = function Xexport 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.ts drops ~1500 lines (~2050 → 586).

Verification

  • tsc -b --force clean
  • npx jest: 475 passed / 12 skipped — identical before and after (behavior-preserving move)
  • Public Game.* API + signatures unchanged

Follow-up

switchDice has weak coverage (flagged in #134); left for a dedicated coverage pass since this phase is a pure move.

Refs #132, #134

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
@nodots
nodots merged commit 1027a6f into refactor/game-decomp-phase4-lifecycle Jul 15, 2026
@nodots
nodots deleted the refactor/game-decomp-phase5-turnflow branch July 15, 2026 18:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant