From 3e2bf8904e50b6c2d585467c13997845298f2332 Mon Sep 17 00:00:00 2001 From: ricoc Date: Tue, 6 May 2025 14:19:01 +0200 Subject: [PATCH 1/4] Comments about board and move --- src/backend/Board.java | 12 ++++++------ src/backend/Move.java | 6 +----- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/backend/Board.java b/src/backend/Board.java index a175569..01ff6ab 100644 --- a/src/backend/Board.java +++ b/src/backend/Board.java @@ -163,7 +163,7 @@ public class Board { // select it as active location selectedX = x; selectedY = y; - highlightedPositions = getValidMoves(board[x][y]); // compute moves + highlightedPositions = getValidMoves(board[x][y]); // compute valid moves } } else { if (x == selectedX && y == selectedY) { @@ -172,7 +172,7 @@ public class Board { selectedY = -1; highlightedPositions.clear(); } else { - // move if valid destination + // allow move if valid destination boolean valid = false; for (int[] pos : highlightedPositions) { if (pos[0] == x && pos[1] == y) { @@ -202,7 +202,7 @@ public class Board { return (x == selectedX && y == selectedY); // true if matching position } - public boolean isHighlighted(int x, int y) { + public boolean isHighlighted(int x, int y) { // checking for a given position if the square is highlighted or not for (int[] pos : highlightedPositions) { if (pos[0] == x && pos[1] == y) { return true; @@ -263,8 +263,8 @@ public class Board { } } break; - - case Rook: +//for each piece, we calculate the positions it can end up in from an initial position + case Rook: addLinearMoves(moves, x, y, piece, 1, 0); addLinearMoves(moves, x, y, piece, -1, 0); addLinearMoves(moves, x, y, piece, 0, 1); @@ -304,7 +304,7 @@ public class Board { case Knight: int[][] jumps = { - {1, 2}, {2, 1}, {-1, 2}, {-2, 1}, + {1, 2}, {2, 1}, {-1, 2}, {-2, 1}, // possible moves for {-1, -2}, {-2, -1}, {1, -2}, {2, -1} }; for (int[] j : jumps) { diff --git a/src/backend/Move.java b/src/backend/Move.java index 6d77bf7..2b49255 100644 --- a/src/backend/Move.java +++ b/src/backend/Move.java @@ -1,11 +1,7 @@ package backend; -import java.util.Optional; +import java.util.ArrayList; -/** - * Represents a chess move, including the starting and ending positions, - * the moving piece, and an optional captured piece. - */ public class Move { } From ea4a1714d089a772997a6152238171500706b5cf Mon Sep 17 00:00:00 2001 From: mathy Date: Tue, 6 May 2025 14:44:40 +0200 Subject: [PATCH 2/4] switched removed --- src/backend/Board.java | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/src/backend/Board.java b/src/backend/Board.java index a175569..baf49c9 100644 --- a/src/backend/Board.java +++ b/src/backend/Board.java @@ -111,21 +111,11 @@ public class Board { } else { // convert each piece of both color into a character Piece piece = board[x][y]; - char pieceChar; - - switch (piece.getType()) { // switch function avoids too many if-else - case King: pieceChar = 'K'; break; - case Queen: pieceChar = 'Q'; break; - case Bishop: pieceChar = 'B'; break; - case Knight: pieceChar = 'N'; break; // N because we already have King - case Rook: pieceChar = 'R'; break; - case Pawn: pieceChar = 'P'; break; - default: pieceChar = '?'; break; // safety net - } + String pieceChar = piece.getType().getSummary(); // Make black pieces in lowercase if (!piece.isWhite()) { - pieceChar = Character.toLowerCase(pieceChar); + pieceChar = pieceChar.toLowerCase(); } str.append(pieceChar).append(" "); // gives structure to the output From 8fd68523efd7a74c4fa46e27bd147c52e6aba411 Mon Sep 17 00:00:00 2001 From: mathy Date: Tue, 6 May 2025 14:59:48 +0200 Subject: [PATCH 3/4] remove switch --- src/backend/Board.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/backend/Board.java b/src/backend/Board.java index baf49c9..239b8cf 100644 --- a/src/backend/Board.java +++ b/src/backend/Board.java @@ -116,6 +116,7 @@ public class Board { // Make black pieces in lowercase if (!piece.isWhite()) { pieceChar = pieceChar.toLowerCase(); + } str.append(pieceChar).append(" "); // gives structure to the output From adb389ddc10c785e37e076d32cbeb259c1da884e Mon Sep 17 00:00:00 2001 From: mathy Date: Tue, 6 May 2025 15:00:42 +0200 Subject: [PATCH 4/4] Merge branch 'master' of https://gitarero.ecam.fr/mathys.balme/OOP_1B6_Project.git --- src/backend/Board.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/backend/Board.java b/src/backend/Board.java index 0a3bdba..0a4e8b2 100644 --- a/src/backend/Board.java +++ b/src/backend/Board.java @@ -116,7 +116,6 @@ public class Board { // Make black pieces in lowercase if (!piece.isWhite()) { pieceChar = pieceChar.toLowerCase(); - } str.append(pieceChar).append(" "); // gives structure to the output