chess/js/controllers
Christoph Wagner 8390862a73
All checks were successful
CI Pipeline / Code Linting (pull_request) Successful in 13s
CI Pipeline / Run Tests (pull_request) Successful in 21s
CI Pipeline / Build Verification (pull_request) Successful in 13s
CI Pipeline / Generate Quality Report (pull_request) Successful in 19s
fix: correct captured piece extraction from Board.movePiece() return value
Fixes critical bug where moves with captures would crash the game.

Root Cause:
- Board.movePiece() returns an object: { captured: pieceOrNull }
- GameController.executeMove() was treating the return value as the piece itself
- This caused move.captured to be { captured: piece } instead of piece
- When GameState.recordMove() tried to access move.captured.color, it was undefined
- Error: "TypeError: undefined is not an object (evaluating 'this.capturedPieces[move.captured.color].push')"

The Fix:
Extract the captured piece from the return object:
  const moveResult = this.board.movePiece(fromRow, fromCol, toRow, toCol);
  captured = moveResult.captured;

This ensures move.captured is the actual Piece object (or null), not wrapped in an object.

Impact:
- Moves with captures now work correctly
- Captured pieces are properly tracked in game state
- UI can now display captured pieces
- Game flow works end-to-end

Testing:
- All 124 unit tests passing 
- Captures properly recorded in capturedPieces arrays
- No regression in non-capture moves

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-23 15:37:05 +01:00
..