promotion
This commit is contained in:
parent
5bfc3c9b37
commit
ebf8687fa5
|
|
@ -1,5 +1,5 @@
|
||||||
BR, , ,BK, ,BR, ,
|
BR, , ,BK, ,BR, ,
|
||||||
BP,BP,BP, , ,BP,BP,BP
|
BP,WP,BP, , ,BP,BP,BP
|
||||||
, , , ,WP, , ,
|
, , , ,WP, , ,
|
||||||
, , , , , , ,
|
, , , , , , ,
|
||||||
, , , , , , ,
|
, , , , , , ,
|
||||||
|
|
|
||||||
|
|
@ -154,6 +154,15 @@ public class Board {
|
||||||
|
|
||||||
this.setPiece(x,y,pieceToMove.getType(),pieceToMove.isWhite());
|
this.setPiece(x,y,pieceToMove.getType(),pieceToMove.isWhite());
|
||||||
Piece movedPiece = this.getPiece(x, y);
|
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) {
|
if (movedPiece != null) {
|
||||||
movedPiece.setMoved(true);
|
movedPiece.setMoved(true);
|
||||||
}
|
}
|
||||||
|
|
@ -281,6 +290,15 @@ public class Board {
|
||||||
if (movedPiece != null) {
|
if (movedPiece != null) {
|
||||||
movedPiece.setMoved(true);
|
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);
|
board.get(ym).set(xm,null);
|
||||||
this.turnColor = !this.turnColor;
|
this.turnColor = !this.turnColor;
|
||||||
this.turnNumber +=1;
|
this.turnNumber +=1;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue