Promotion fixed
This commit is contained in:
parent
747beeaec5
commit
de01655fbb
|
|
@ -2,9 +2,10 @@
|
|||
package backend;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import java.util.Scanner;
|
||||
public class Board {
|
||||
|
||||
private final Scanner scanner = new Scanner(System.in);
|
||||
private int selectedX = -1; // negative value means impossible x and y so unselected
|
||||
private int selectedY = -1;
|
||||
|
||||
|
|
@ -186,6 +187,10 @@ public class Board {
|
|||
board[3][y].setY(y);
|
||||
}
|
||||
}
|
||||
if (pieceToMove.getType() == PieceType.Pawn && (y == 0 || y == 7)) {
|
||||
PieceType promotionType = askPromotionChoice(pieceToMove.isWhite());
|
||||
board[x][y] = new Piece(x, y, promotionType, pieceToMove.isWhite());
|
||||
}
|
||||
|
||||
// Handle en passant capture
|
||||
if (pieceToMove.getType() == PieceType.Pawn && board[x][y] == null && x != selectedX) {
|
||||
|
|
@ -291,6 +296,23 @@ public class Board {
|
|||
System.out.println(toString());
|
||||
}
|
||||
|
||||
private PieceType askPromotionChoice(boolean isWhite) {
|
||||
System.out.println("Choose piece to promote to:");
|
||||
System.out.println("Enter Q for Queen, R for Rook, B for Bishop, N for Knight");
|
||||
|
||||
while (true) {
|
||||
String input = scanner.nextLine().trim().toUpperCase();
|
||||
switch (input) {
|
||||
case "Q": return PieceType.Queen;
|
||||
case "R": return PieceType.Rook;
|
||||
case "B": return PieceType.Bishop;
|
||||
case "N": return PieceType.Knight;
|
||||
default:
|
||||
System.out.println("Invalid choice. Please enter Q, R, B, or N.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void undoLastMove() {
|
||||
// TODO
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue