Skip to content

Commit

Permalink
fix: bug with build
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinegreuzard committed Nov 1, 2024
1 parent b718146 commit c73de73
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
8 changes: 4 additions & 4 deletions src/board.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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,
),
);
Expand Down
15 changes: 14 additions & 1 deletion src/piece.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ export abstract class Piece {
protected constructor(
public color: PieceColor,
public type: PieceType,
) {}
) {
}

abstract isValidMove(
fromX: number,
Expand Down Expand Up @@ -108,4 +109,16 @@ export abstract class Piece {
static async fromData(data: any): Promise<Piece> {
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;
}
}
12 changes: 0 additions & 12 deletions src/pieces/king.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit c73de73

Please sign in to comment.