OpenChess Development Assistant
Expert assistant for developing a chess game built with Lua and the LÖVE (Love2D) framework. This skill helps implement chess rules, debug game logic, improve UI/UX, and extend features.
Project Context
This chess game uses:
**Language**: Lua 5.1+**Framework**: LÖVE 11.0+**Graphics**: Pixel art with nearest-neighbor filtering**Resolution**: 690x690 window, 180x180 board scaled 3x**Assets**: Located in `./assets/` directoryCode Architecture
Key Variables
`gameState`: Controls menu/playing states`pieces`: 2D array storing piece objects`board`: Initial board layout template`selectedPiece`: Currently selected piece`currentPlayer`: "white" or "black"`gameStarted`: Tracks if a game is in progressCore Functions
`initializeBoard()`: Sets up initial piece positions`isValidMove()`: Validates piece movements per chess rules`isKingInCheck()`: Detects check conditions`wouldMoveLeaveKingInCheck()`: Prevents illegal moves`getValidMoves()`: Returns all legal moves for a pieceInstructions
When working on this project, follow these steps:
1. Understanding the Request
Identify if the task involves chess rules, UI/UX, game state, or debuggingCheck if it affects existing move validation or check detectionConsider impact on current game state preservation2. Reading Relevant Code
Always read the main game file (likely `main.lua`) before making changesCheck asset dimensions in `./assets/` when working on graphicsReview coordinate system (1-based indexing, 22.5px per square, 3x scaling)3. Implementing Chess Features
When adding missing chess rules:
1. **Castling**: Check `isValidMove()`, verify king/rook haven't moved, path is clear, not castling through check
2. **En Passant**: Track last pawn double-move, validate capture position
3. **Pawn Promotion**: Detect pawn reaching end rank, implement promotion UI
4. **Checkmate**: Extend `isKingInCheck()` to verify if any legal moves exist
5. **Stalemate**: Check if no legal moves exist but king not in check
4. Code Style Guidelines
Use local variables when possibleKeep functions focused and single-purposeMaintain consistent indentation (4 spaces)Comment complex chess logic thoroughlyUse meaningful variable names5. Testing Approach
```bash
Run the game
love .
```
Manual testing required (no automated tests)Test edge cases: moving into check, capture sequences, special movesVerify `currentPlayer` switches correctlyCheck that menu (ESC) preserves game state6. Performance Considerations
`getValidMoves()` is called every frame when a piece is selectedConsider caching valid moves if performance issues ariseUse simple 2D array lookups for board stateMinimize redundant calculations in move validationKnown Limitations
Missing Chess Rules
Castling (king-side and queen-side)En passant capturePawn promotionFifty-move ruleThreefold repetitionGame End Conditions
Checkmate detectionStalemate detectionDraw conditionsUI/UX Improvements
Move history displayCaptured pieces displayTimer/clock systemSound effectsAnimations for piece movementAdvanced Features
Save/load game functionalityPGN export/importAI opponentOnline multiplayerDifferent board themesDebugging Tips
Inspect `pieces` array for current board stateUse `print()` statements to debug move validationVerify `currentPlayer` switches correctly after movesCheck coordinate calculations (1-based indexing)Test edge cases with king in check scenariosVerify board square size calculations (22.5px * 3 = 67.5px display size)Example Usage
**User**: "Implement castling for both king-side and queen-side"
**Assistant approach**:
1. Read `main.lua` to understand current move validation
2. Add castling tracking variables (king/rook moved flags)
3. Implement castling logic in `isValidMove()`
4. Verify path is clear and not castling through check
5. Update board state to move both king and rook
6. Test with manual gameplay
**User**: "Add a move history display"
**Assistant approach**:
1. Create data structure to track moves
2. Design UI layout for history panel
3. Update move execution code to log moves
4. Implement rendering for move history
5. Test that history persists correctly
Important Notes
The game prevents illegal moves that leave the king in checkAll piece movements must follow standard chess rulesCoordinate system uses 1-based indexing (Lua standard)Menu system (ESC) must preserve game stateAsset scaling is critical: board squares are 22.5px base, 67.5px displayed