Restructured project from nested workspace pattern to flat single-repo layout. This eliminates redundant nesting and consolidates all project files under version control. ## Migration Summary **Before:** ``` alex/ (workspace, not versioned) ├── chess-game/ (git repo) │ ├── js/, css/, tests/ │ └── index.html └── docs/ (planning, not versioned) ``` **After:** ``` alex/ (git repo, everything versioned) ├── js/, css/, tests/ ├── index.html ├── docs/ (project documentation) ├── planning/ (historical planning docs) ├── .gitea/ (CI/CD) └── CLAUDE.md (configuration) ``` ## Changes Made ### Structure Consolidation - Moved all chess-game/ contents to root level - Removed redundant chess-game/ subdirectory - Flattened directory structure (eliminated one nesting level) ### Documentation Organization - Moved chess-game/docs/ → docs/ (project documentation) - Moved alex/docs/ → planning/ (historical planning documents) - Added CLAUDE.md (workspace configuration) - Added IMPLEMENTATION_PROMPT.md (original project prompt) ### Version Control Improvements - All project files now under version control - Planning documents preserved in planning/ folder - Merged .gitignore files (workspace + project) - Added .claude/ agent configurations ### File Updates - Updated .gitignore to include both workspace and project excludes - Moved README.md to root level - All import paths remain functional (relative paths unchanged) ## Benefits ✅ **Simpler Structure** - One level of nesting removed ✅ **Complete Versioning** - All documentation now in git ✅ **Standard Layout** - Matches open-source project conventions ✅ **Easier Navigation** - Direct access to all project files ✅ **CI/CD Compatible** - All workflows still functional ## Technical Validation - ✅ Node.js environment verified - ✅ Dependencies installed successfully - ✅ Dev server starts and responds - ✅ All core files present and accessible - ✅ Git repository functional ## Files Preserved **Implementation Files:** - js/ (3,517 lines of code) - css/ (4 stylesheets) - tests/ (87 test cases) - index.html - package.json **CI/CD Pipeline:** - .gitea/workflows/ci.yml - .gitea/workflows/release.yml **Documentation:** - docs/ (12+ documentation files) - planning/ (historical planning materials) - README.md **Configuration:** - jest.config.js, babel.config.cjs, playwright.config.js - .gitignore (merged) - CLAUDE.md 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
11 KiB
Component Specifications
Core Components
1. ChessBoard
Responsibility: Manages the 8x8 chess board representation and coordinates.
Properties:
squares: Array[64] of Square objectsactivePiece: Reference to currently selected piecelegalMoves: Array of legal destination squares
Methods:
getSquare(file, rank): Get square at positionsetPiece(square, piece): Place piece on squareremovePiece(square): Remove piece from squaregetPiece(square): Get piece at squarehighlightSquares(squares): Visual highlightclearHighlights(): Remove highlightsisSquareOccupied(square): Check occupancygetSquareColor(square): Get square color (light/dark)
Events Emitted:
square-clicked: User clicks a squarepiece-selected: Piece is selectedpiece-deselected: Piece is deselected
Dependencies:
- Square
- ChessPiece (for rendering)
2. ChessPiece
Responsibility: Represents individual chess pieces with movement rules.
Properties:
type: PieceType (pawn, knight, bishop, rook, queen, king)color: Color (white, black)position: Current squarehasMoved: Boolean (for castling, en passant)moveCount: Number of moves made
Methods:
getPossibleMoves(board): Get all pseudo-legal movesgetLegalMoves(board, gameState): Get truly legal movescanMoveTo(square, board): Check if move is validclone(): Deep copy of piecegetNotation(): Get piece notation (K, Q, R, B, N, P)getImagePath(): Get piece image asset path
Piece-Specific Logic:
- Pawn: Forward movement, diagonal capture, en passant, promotion
- Knight: L-shaped movement, jump over pieces
- Bishop: Diagonal movement
- Rook: Straight movement, castling
- Queen: Combination of bishop and rook
- King: One square in any direction, castling
Events Emitted:
piece-moved: Piece completes movementpiece-captured: Piece is capturedpiece-promoted: Pawn promotion
Dependencies:
- Board (for move validation)
- MoveValidator
3. GameEngine
Responsibility: Enforces chess rules and manages game state.
Properties:
gameState: Current game state objectcurrentPlayer: Current player's turnmoveHistory: Array of all movescapturedPieces: Object with arrays per colorgameStatus: Status (active, check, checkmate, stalemate, draw)
Methods:
initializeGame(): Set up new gameexecuteMove(from, to): Perform a moveundoMove(): Undo last moveredoMove(): Redo undone moveisCheck(color): Check if king is in checkisCheckmate(color): Check for checkmateisStalemate(): Check for stalemateisDraw(): Check for draw conditionsswitchTurn(): Change active playergetGameState(): Get current state snapshotloadGameState(state): Restore game state
Game State Object:
{
board: BoardState,
currentPlayer: 'white' | 'black',
moveNumber: number,
halfMoveClock: number,
enPassantSquare: Square | null,
castlingRights: {
whiteKingSide: boolean,
whiteQueenSide: boolean,
blackKingSide: boolean,
blackQueenSide: boolean
},
lastMove: Move | null,
status: GameStatus
}
Events Emitted:
game-started: New game beginsmove-executed: Move completedturn-changed: Player turn switchescheck-detected: King in checkgame-over: Game ends (checkmate/stalemate/draw)
Dependencies:
- ChessBoard
- MoveValidator
- GameHistory
4. MoveValidator
Responsibility: Validates move legality according to chess rules.
Properties:
validationCache: Map for caching validation results
Methods:
isMoveLegal(from, to, gameState): Full legality checkisPseudoLegal(from, to, board): Basic movement checkwouldExposeKing(move, gameState): Check detectionvalidateCastling(move, gameState): Castling validationvalidateEnPassant(move, gameState): En passant validationvalidatePromotion(move): Pawn promotion validationgetCheckingPieces(color, gameState): Find pieces giving checkisSquareAttacked(square, byColor, gameState): Attack detectionclearCache(): Clear validation cache
Validation Rules:
- Piece movement follows type-specific rules
- Move doesn't leave own king in check
- Special moves (castling, en passant) meet conditions
- Target square is valid (on board, not occupied by own piece)
Events Emitted:
validation-failed: Move rejected with reason
Dependencies:
- ChessPiece
- ChessBoard
- GameState
5. GameController
Responsibility: Orchestrates game flow and user interaction.
Properties:
gameEngine: Reference to GameEngineboardView: Reference to visual boardselectedSquare: Currently selected squaregameMode: Mode (pvp, pva, ava)playerColors: Map of player to color
Methods:
handleSquareClick(square): Process square selectionhandlePieceDrag(piece, square): Process drag-and-dropstartNewGame(config): Initialize new gameresignGame(): End game with resignationofferDraw(): Propose drawrequestUndo(): Request move undosaveGame(): Persist current gameloadGame(saveData): Restore saved gameconfigureGame(options): Update settings
User Interaction Flow:
- User clicks piece → Highlight legal moves
- User clicks destination → Validate and execute move
- Update UI → Switch turn → Check game status
Events Emitted:
user-action: User performs actiongame-saved: Game state persistedgame-loaded: Game state restored
Dependencies:
- GameEngine
- ChessBoardView
- UIController
- AIPlayer (optional)
6. MoveGenerator
Responsibility: Generates all possible moves for position analysis.
Properties:
generationCache: Map for move generation results
Methods:
generateAllMoves(gameState, color): All legal moves for colorgeneratePieceMoves(piece, gameState): Moves for specific piecegenerateCaptures(gameState, color): Only capturing movesgenerateQuietMoves(gameState, color): Non-capturing movesperft(depth, gameState): Performance test (move counting)clearCache(): Clear generation cache
Optimization:
- Lazy evaluation for move generation
- Bitboard operations for efficiency
- Move ordering for search algorithms
Events Emitted:
- None (pure computation)
Dependencies:
- MoveValidator
- ChessBoard
- GameState
7. GameHistory
Responsibility: Tracks move history and enables undo/redo.
Properties:
moves: Array of Move objectspositions: Array of board positions (for repetition detection)currentIndex: Current position in history
Methods:
addMove(move): Record a movegetMove(index): Retrieve specific movegetAllMoves(): Get complete historyundo(): Move back one positionredo(): Move forward one positioncanUndo(): Check if undo availablecanRedo(): Check if redo availableclear(): Reset historyexportPGN(): Export as PGN notationexportJSON(): Export as JSONisThreefoldRepetition(): Detect draw by repetition
Move Object:
{
from: Square,
to: Square,
piece: PieceType,
captured: PieceType | null,
promotion: PieceType | null,
isCheck: boolean,
isCheckmate: boolean,
isCastling: boolean,
isEnPassant: boolean,
notation: string,
timestamp: number
}
Events Emitted:
history-updated: Move added to historyhistory-cleared: History reset
Dependencies:
- Move notation system
8. UIController
Responsibility: Manages user interface and visual feedback.
Properties:
selectedPiece: Currently selected piece elementdraggedPiece: Piece being draggedtheme: Current visual theme
Methods:
renderBoard(): Draw complete boardrenderPiece(piece, square): Draw piece on squareanimateMove(from, to): Animate piece movementshowLegalMoves(moves): Highlight valid destinationshideLegalMoves(): Remove highlightsupdateGameStatus(status): Display game stateshowPromotion(square): Display promotion dialogplaySound(event): Play sound effectupdateCapturedPieces(pieces): Display captured piecesenableDragAndDrop(): Enable drag-and-dropdisableDragAndDrop(): Disable interactions
Visual Feedback:
- Highlight selected piece
- Highlight legal move squares
- Animate piece movement
- Show check/checkmate indicators
- Display current player turn
- Show captured pieces
Events Emitted:
ui-click: User clicks elementui-drag-start: Drag beginsui-drag-end: Drag endspromotion-selected: User selects promotion piece
Dependencies:
- ChessBoardView
- ThemeManager
9. AIPlayer (Optional)
Responsibility: Provides computer opponent with configurable difficulty.
Properties:
difficulty: Difficulty level (1-10)thinkingTime: Max time per move (ms)searchDepth: Minimax search depthevaluator: Position evaluation function
Methods:
calculateMove(gameState): Determine best moveevaluatePosition(gameState): Score positionminimax(depth, alpha, beta, gameState): Search algorithmorderMoves(moves): Move ordering for pruninggetOpeningMove(gameState): Opening book lookupsetDifficulty(level): Adjust AI strength
AI Levels:
- Random: Random legal moves
- Beginner: Material-only evaluation, depth 2
- Intermediate: Positional evaluation, depth 3-4
- Advanced: Full evaluation, depth 5-6
- Expert: Advanced pruning, depth 7+
Evaluation Factors:
- Material count (piece values)
- Piece positioning (piece-square tables)
- King safety
- Pawn structure
- Mobility
- Center control
Events Emitted:
ai-thinking: AI calculation startedai-move-ready: AI move calculated
Dependencies:
- MoveGenerator
- MoveEvaluator
- GameState
10. ThemeManager
Responsibility: Manages visual themes and customization.
Properties:
currentTheme: Active theme objectavailableThemes: Map of registered themes
Methods:
setTheme(themeName): Apply themegetTheme(): Get current themeregisterTheme(theme): Add custom themeloadTheme(themeData): Load theme from dataexportTheme(): Export current theme
Theme Object:
{
name: string,
lightSquares: color,
darkSquares: color,
highlightColor: color,
legalMoveColor: color,
selectedPieceColor: color,
checkColor: color,
pieceSet: string,
boardBorder: style
}
Events Emitted:
theme-changed: Theme switched
Dependencies:
- CSS custom properties
Component Interaction Map
User Input → UIController → GameController → GameEngine
↓ ↓
MoveValidator ← ChessBoard
↓ ↓
GameHistory ← ChessPiece
AIPlayer → MoveGenerator → MoveValidator → GameEngine
Initialization Sequence
- Create ChessBoard instance
- Initialize GameEngine with board
- Create MoveValidator with engine
- Initialize GameController with engine
- Set up UIController with board view
- Create GameHistory tracker
- Initialize AIPlayer (if enabled)
- Start new game