From ebf8687fa5ea1a105215c44ffe5eecda864e437f Mon Sep 17 00:00:00 2001 From: Romain Murphy Date: Wed, 30 Apr 2025 16:17:39 +0200 Subject: [PATCH] promotion --- OOP_2B1_Project/TEst | 2 +- OOP_2B1_Project/src/backend/Board.java | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/OOP_2B1_Project/TEst b/OOP_2B1_Project/TEst index eaf2ba6..1f2bf6c 100644 --- a/OOP_2B1_Project/TEst +++ b/OOP_2B1_Project/TEst @@ -1,5 +1,5 @@ BR, , ,BK, ,BR, , -BP,BP,BP, , ,BP,BP,BP +BP,WP,BP, , ,BP,BP,BP , , , ,WP, , , , , , , , , , , , , , , , , diff --git a/OOP_2B1_Project/src/backend/Board.java b/OOP_2B1_Project/src/backend/Board.java index 94e7226..cbe8c9e 100644 --- a/OOP_2B1_Project/src/backend/Board.java +++ b/OOP_2B1_Project/src/backend/Board.java @@ -154,6 +154,15 @@ public class Board { this.setPiece(x,y,pieceToMove.getType(),pieceToMove.isWhite()); Piece movedPiece = this.getPiece(x, y); + if (movedPiece instanceof Pawn) { + int promotionRow = movedPiece.isWhite() ? 0 : 7; + if (y == promotionRow) { + // Replace pawn with promoted piece +// System.out.println() + this.setPiece(x,y,PieceType.Queen,pieceToMove.isWhite()); + // You can replace Queen with any piece type as needed + } + } if (movedPiece != null) { movedPiece.setMoved(true); } @@ -281,6 +290,15 @@ public class Board { if (movedPiece != null) { movedPiece.setMoved(true); } + if (movedPiece instanceof Pawn) { + int promotionRow = movedPiece.isWhite() ? 0 : 7; + if (y == promotionRow) { + // Replace pawn with promoted piece +// System.out.println() + this.setPiece(x,y,PieceType.Queen,pieceToMove.isWhite()); + // You can replace Queen with any piece type as needed + } + } board.get(ym).set(xm,null); this.turnColor = !this.turnColor; this.turnNumber +=1;