Promotion fixed
This commit is contained in:
parent
747beeaec5
commit
de01655fbb
|
|
@ -2,9 +2,10 @@
|
||||||
package backend;
|
package backend;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Scanner;
|
||||||
public class Board {
|
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 selectedX = -1; // negative value means impossible x and y so unselected
|
||||||
private int selectedY = -1;
|
private int selectedY = -1;
|
||||||
|
|
||||||
|
|
@ -186,6 +187,10 @@ public class Board {
|
||||||
board[3][y].setY(y);
|
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
|
// Handle en passant capture
|
||||||
if (pieceToMove.getType() == PieceType.Pawn && board[x][y] == null && x != selectedX) {
|
if (pieceToMove.getType() == PieceType.Pawn && board[x][y] == null && x != selectedX) {
|
||||||
|
|
@ -290,6 +295,23 @@ public class Board {
|
||||||
clearConsole();
|
clearConsole();
|
||||||
System.out.println(toString());
|
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() {
|
public void undoLastMove() {
|
||||||
// TODO
|
// TODO
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue