From c73de73c49867716aaa871f3c41e7efb0882b738 Mon Sep 17 00:00:00 2001 From: antoinegreuzard Date: Fri, 1 Nov 2024 17:49:23 +0100 Subject: [PATCH] fix: bug with build --- src/board.ts | 8 ++++---- src/piece.ts | 15 ++++++++++++++- src/pieces/king.ts | 12 ------------ 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/board.ts b/src/board.ts index 6ce79e7..e9e9558 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)) { @@ -641,9 +641,9 @@ export class Board implements BoardInterface { row.map((piece) => piece ? Object.create( - Object.getPrototypeOf(piece), - Object.getOwnPropertyDescriptors(piece), - ) + Object.getPrototypeOf(piece), + Object.getOwnPropertyDescriptors(piece), + ) : null, ), ); diff --git a/src/piece.ts b/src/piece.ts index c72a9ed..48c6b4e 100644 --- a/src/piece.ts +++ b/src/piece.ts @@ -58,7 +58,8 @@ export abstract class Piece { protected constructor( public color: PieceColor, public type: PieceType, - ) {} + ) { + } abstract isValidMove( fromX: number, @@ -108,4 +109,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; + } } diff --git a/src/pieces/king.ts b/src/pieces/king.ts index a847b1f..c643ff3 100644 --- a/src/pieces/king.ts +++ b/src/pieces/king.ts @@ -58,16 +58,4 @@ export class King extends Piece { return false; } - - // Nouvelle méthode pour vérifier les menaces sans règles spécifiques du roi - public static 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; - } }