From 3eb7d3ea3f18222c340faa23566fd3431ca9fde4 Mon Sep 17 00:00:00 2001 From: lrave Date: Fri, 16 May 2025 09:48:53 +0200 Subject: [PATCH 1/3] removed some commented methods --- src/backend/Board.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/backend/Board.java b/src/backend/Board.java index 1934f34..e38846c 100644 --- a/src/backend/Board.java +++ b/src/backend/Board.java @@ -191,14 +191,12 @@ public class Board { if(pieceToMove.getType() == PieceType.King && Math.abs(x - selectedX)==2) { y = selectedY; if (x == 6) { - System.out.println("pipi au caca"); board[5][y] = board[7][y]; board[7][y] = null; board[5][y].setMoved(true); board[5][y].setX(5); board[5][y].setY(y); } else if (x == 2) { - System.out.println("pipi"); //System.out.println(board [3][y]); //System.out.println(board [0][y]); board [3][y] = board[0][y]; @@ -221,7 +219,7 @@ public class Board { selectedX = -1; selectedY = -1; highlightedPositions.clear(); - //clearConsole(); + clearConsole(); System.out.println(toString()); } } From d734e3f13d6f7f9415b212e4e8ca8db0189c7c49 Mon Sep 17 00:00:00 2001 From: lrave Date: Fri, 16 May 2025 10:57:53 +0200 Subject: [PATCH 2/3] Promotion --- src/backend/Board.java | 24 +++++++++++++++++++++++- src/backend/Piece.java | 1 + 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/backend/Board.java b/src/backend/Board.java index e38846c..3124a83 100644 --- a/src/backend/Board.java +++ b/src/backend/Board.java @@ -2,8 +2,10 @@ package backend; import java.util.ArrayList; -public class Board { +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; @@ -208,8 +210,13 @@ public class Board { board[3][y].setY(y); } } + board[x][y] = new Piece(x, y, pieceToMove.getType(), pieceToMove.isWhite()); board[selectedX][selectedY] = null; + if (pieceToMove.getType() == PieceType.Pawn && (y == 0 || y == 7)) { + PieceType promotionType = askPromotionChoice(pieceToMove.isWhite()); + board[x][y] = new Piece(x, y, promotionType, pieceToMove.isWhite()); + } board[x][y].setMoved(true); incrementTurn(); @@ -331,7 +338,22 @@ public class Board { clearConsole(); 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."); + } + } + } /* additional functionality to implement later */ public void undoLastMove() { diff --git a/src/backend/Piece.java b/src/backend/Piece.java index e681720..579727d 100644 --- a/src/backend/Piece.java +++ b/src/backend/Piece.java @@ -195,4 +195,5 @@ public class Piece { ny += dy; } } + } \ No newline at end of file From a2567d48a5db77cf2aca153cad39c9b7115135c8 Mon Sep 17 00:00:00 2001 From: lrave Date: Fri, 16 May 2025 11:27:12 +0200 Subject: [PATCH 3/3] commenting --- src/backend/Board.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/backend/Board.java b/src/backend/Board.java index 3124a83..fed66d8 100644 --- a/src/backend/Board.java +++ b/src/backend/Board.java @@ -5,8 +5,8 @@ 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 final Scanner scanner = new Scanner(System.in); // to be able to ask user input and analyze it (from library scanner) + private int selectedX = -1; // negative value means impossible x and y that way before the first move, acts unselected private int selectedY = -1; private int turnNumber = 0; // tracks current turn