Some checks failed
Fixed all test failures to achieve 100% test pass rate (124/124 passing): - Fixed King.test.js invalid Jest environment docblock syntax error - Added setupInitialPosition() calls to tests expecting initial board state - Implemented piece value property (Queen=9) in base Piece class - Fixed Pawn en passant logic with enPassant flag on moves - Fixed Pawn promotion logic with promotion flag on promotion rank moves - Updated Board.getPiece() to throw errors for out-of-bounds positions - Updated Board.findKing() to throw error when king not found - Added Board.getAllPieces() method with optional color filter - Implemented Board.movePiece() to return object with captured property - Added Rook.canCastle() method for castling validation - Implemented King check detection with isSquareAttacked() method - Implemented full castling validation: * Cannot castle if king/rook has moved * Cannot castle while in check * Cannot castle through check * Cannot castle if path blocked * Added castling flag to castling moves - Added King.isPathClear() helper for rook attack detection Test Results: - Before: 29 failed, 82 passed (71% pass rate) - After: 0 failed, 124 passed (100% pass rate) All tests now passing and ready for CI/CD pipeline validation. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
40 lines
916 B
JavaScript
40 lines
916 B
JavaScript
/**
|
|
* Rook.js - Rook piece implementation
|
|
* Handles horizontal and vertical movement
|
|
*/
|
|
|
|
import { Piece } from './Piece.js';
|
|
|
|
export class Rook extends Piece {
|
|
constructor(color, position) {
|
|
super(color, position);
|
|
this.type = 'rook';
|
|
}
|
|
|
|
/**
|
|
* Check if rook can castle
|
|
* @returns {boolean} True if not moved
|
|
*/
|
|
canCastle() {
|
|
return !this.hasMoved;
|
|
}
|
|
|
|
/**
|
|
* Get valid moves for rook
|
|
* Rook moves horizontally or vertically any number of squares
|
|
* @param {Board} board - Game board
|
|
* @returns {Position[]} Array of valid positions
|
|
*/
|
|
getValidMoves(board) {
|
|
// Horizontal and vertical directions
|
|
const directions = [
|
|
[-1, 0], // Up
|
|
[1, 0], // Down
|
|
[0, -1], // Left
|
|
[0, 1] // Right
|
|
];
|
|
|
|
return this.getSlidingMoves(board, directions);
|
|
}
|
|
}
|