Refactor: Extract game types, board ops, and UI components - #17
Conversation
Break up large monolithic files into focused, single-responsibility modules: Engine layer: - Extract types.ts (game type definitions) - Extract constants.ts (BOARD_SIZE, TOTAL_SHEEP, SHEEP_TO_WIN) - Extract boardOps.ts (adjacency, captures, valid moves) - Slim gameEngine.ts to state transitions + re-exports for backward compat UI layer: - Extract BoardCell.tsx (cell rendering + animations) from Board.tsx - Extract BoardLines.tsx (grid + diagonal rendering) from Board.tsx - Extract MiniBoard.tsx (animated tutorial board) from TutorialScreen.tsx - Extract tutorialData.ts (step definitions) from TutorialScreen.tsx - Extract WinModal.tsx (victory overlay) from GameScreen.tsx Hooks: - Extract useGameEvents.ts (sound/haptic/animation event detection) - Extract useAIPlayer.ts (AI move orchestration + thinking pulse) Shared utilities: - Add theme.ts for centralized color palette - Add boardLayout.ts for shared board dimension calculations All 101 existing tests pass unchanged. https://claude.ai/code/session_01CfaghKuVR5AAttkwx96CgH
PR SummaryMedium Risk Overview Extracts UI and side-effect logic into dedicated modules: Introduces reusable hooks and shared styling utilities by moving game event side effects to Written by Cursor Bugbot for commit 48736f7. This will update automatically on new commits. Configure here. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
| width: 20, | ||
| height: 20, | ||
| borderRadius: 10, | ||
| backgroundColor: colors.validMove, |
There was a problem hiding this comment.
Tutorial highlighted cell opacity changed during refactoring
Low Severity
The tutorial mini board's highlighted cell backgroundColor was originally 'rgba(76, 175, 80, 0.4)' but now uses colors.validMove which is 'rgba(76, 175, 80, 0.5)'. The original tutorial intentionally used a more transparent green (0.4 alpha) than the main board's valid move indicator (0.5 alpha), but the refactoring consolidated both to the same colors.validMove value, losing the distinction.


Summary
This PR refactors the codebase to improve modularity and maintainability by extracting shared types, constants, board operations, and UI components into dedicated modules. Game logic remains unchanged; this is purely a structural reorganization.
Type of Change
BoardCellandBoardLines)WinModal,MiniBoard,tutorialData)boardLayout.ts,theme.ts)Changes Overview
New Modules Created
src/engine/types.ts— Centralized type definitionsPiece,Turn,Phase,Position,GameMode,DifficultyGameConfig,GameMove,GameStatesrc/engine/constants.ts— Game constantsBOARD_SIZE = 5,TOTAL_SHEEP = 20,SHEEP_TO_WIN = 5src/engine/boardOps.ts— Board utility functionsisInBounds(),hasDiagonals(),getNeighbors(),getCaptureTargets(),getValidMovesForPiece()src/theme.ts— Centralized color palettesrc/utils/boardLayout.ts— Shared board layout calculationsBOARD_WIDTH,CELL_SIZE,PIECE_SIZE,DOT_SIZE,MINI_BOARD_WIDTH,MINI_CELL, etc.hasDiag()helper functionsrc/components/BoardCell.tsx— Extracted cell componentBoard.tsxsrc/components/BoardLines.tsx— Extracted board lines componentBoard.tsxsrc/components/WinModal.tsx— Extracted win modalGameScreen.tsxsrc/components/MiniBoard.tsx— Extracted mini board componentTutorialScreen.tsxsrc/components/tutorialData.ts— Tutorial step definitionsTutorialStepData,PiecePlacement,AnimStepinterfacesSTEPSarray with all 7 tutorial stepsTutorialScreen.tsxsrc/hooks/useGameEvents.ts— Game event detection hookGameScreen.tsxsrc/hooks/useAIPlayer.ts— AI player orchestration hookGameScreen.tsxModified Files
src/engine/gameEngine.ts— Now re-exports types and functions from new modules for backward compatibilitysrc/components/TutorialScreen.tsx— ImportsSTEPSfromtutorialData.ts,MiniBoardfromMiniBoard.tsxsrc/components/GameScreen.tsx— ImportsWinModal,useGameEvents,useAIPlayer,colorssrc/components/Board.tsx— ImportsBoardCell,BoardLines, usesboardLayout.tsconstantshttps://claude.ai/code/session_01CfaghKuVR5AAttkwx96CgH