diff --git a/src/board.ts b/src/board.ts index 6ce79e7..8076a8c 100644 --- a/src/board.ts +++ b/src/board.ts @@ -499,7 +499,7 @@ export class Board implements BoardInterface { if (piece && piece.color !== color) { // Utilise `isThreatenedMove` pour éviter la récursion infinie if (piece.type === PieceType.KING) { - if (King.isThreatenedMove(fromX, fromY, x, y)) { + if (piece.isThreatenedMove(fromX, fromY, x, y)) { return true; } } else if (piece.isValidMove(fromX, fromY, x, y, this)) { diff --git a/src/piece.ts b/src/piece.ts index c72a9ed..1342147 100644 --- a/src/piece.ts +++ b/src/piece.ts @@ -108,4 +108,16 @@ export abstract class Piece { static async fromData(data: any): Promise { return await createPiece(data.type, data.color); } + + // Nouvelle méthode pour vérifier les menaces sans règles spécifiques du roi + public isThreatenedMove( + fromX: number, + fromY: number, + toX: number, + toY: number, + ): boolean { + const dx = Math.abs(toX - fromX); + const dy = Math.abs(toY - fromY); + return dx <= 1 && dy <= 1; + } }