From b7c1e9b497e8d3c851486bd0075c181d800cf1dc Mon Sep 17 00:00:00 2001 From: lrave Date: Tue, 6 May 2025 14:08:08 +0200 Subject: [PATCH 1/6] comment board --- src/backend/Board.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/backend/Board.java b/src/backend/Board.java index a175569..eedfbb4 100644 --- a/src/backend/Board.java +++ b/src/backend/Board.java @@ -7,8 +7,8 @@ public class Board { private int selectedX = -1; // negative value means impossible x and y so unselected private int selectedY = -1; - private int turnNumber = 0; // track current turn - private int width; + private int turnNumber = 0; // tracks current turn + private int width; // enables to define the dimensions of board private int height; private Piece[][] board; // 2D array chess board private ArrayList highlightedPositions = new ArrayList<>(); // list of valid positions to highlight @@ -16,7 +16,7 @@ public class Board { public Board(int colNum, int lineNum) { this.width = colNum; this.height = lineNum; - this.board = new Piece[width][height]; // first empty board + this.board = new Piece[width][height]; // first empty board *********REVIEW************ clearConsole(); System.out.println(toString()); // print the chess at the beginning of the game } From 2c410e4eb75cc7643db69ce727856b1b41b652dc Mon Sep 17 00:00:00 2001 From: lrave Date: Tue, 6 May 2025 14:16:22 +0200 Subject: [PATCH 2/6] Additional comment board --- src/backend/Board.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/backend/Board.java b/src/backend/Board.java index eedfbb4..1dd976e 100644 --- a/src/backend/Board.java +++ b/src/backend/Board.java @@ -29,28 +29,28 @@ public class Board { return height; } - // new piece on the board at x,y + // new piece on the board at x,y (More specifically changes the empty cell of coordinates x,y with a new chess piece) public void setPiece(boolean isWhite, PieceType type, int x, int y) { board[x][y] = new Piece(x, y, type, isWhite); } public boolean isTurnWhite() { - if (turnNumber % 2 == 0) { // even turns including 0 are white's ones + if (turnNumber % 2 == 0) { // even turns including 0 are white's ones (% calculates the reminder of the euclidean division) return true; } else { // same reasoning, odd turns are black's ones return false; } } - public int getTurnNumber() { // these classes change the turn and the increment one solves a problem of infinite loop - return turnNumber; + public int getTurnNumber() { // this class enables to obtain the current turn number while increment adds 1 to this value for each turn + return turnNumber; // Necessarly in two functions to get rid of an infinite loop ****WHY**** } public void incrementTurn() { turnNumber++; } - // set up the chess board taking it as a matrix + // set up the classic chess board taking it as a matrix and putting each corresponding starting piece at its place 0,0 is the top left spot of the board public void populateBoard() { // Black setPiece(false, PieceType.Rook, 0, 0); From 3e2bf8904e50b6c2d585467c13997845298f2332 Mon Sep 17 00:00:00 2001 From: ricoc Date: Tue, 6 May 2025 14:19:01 +0200 Subject: [PATCH 3/6] 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 b3405ceecb526ee3ff3dc5b065a812f148c9dae4 Mon Sep 17 00:00:00 2001 From: lrave Date: Tue, 6 May 2025 14:36:43 +0200 Subject: [PATCH 4/6] comment on user touch start game --- src/backend/Board.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/Board.java b/src/backend/Board.java index 1dd976e..de0cc85 100644 --- a/src/backend/Board.java +++ b/src/backend/Board.java @@ -157,7 +157,7 @@ public class Board { // user clicks on the board public void userTouch(int x, int y) { - if (selectedX == -1 && selectedY == -1) { + if (selectedX == -1 && selectedY == -1) { // ******REVIEW****** Faudrait pas mettre || ? // check if the position is empty and the color if (board[x][y] != null && board[x][y].isWhite() == isTurnWhite()) { // select it as active location From c0cc47cf563bb557b8c63cc71dadf59c32caaee8 Mon Sep 17 00:00:00 2001 From: lrave Date: Tue, 6 May 2025 14:48:39 +0200 Subject: [PATCH 5/6] console class created --- 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 de0cc85..24cc72b 100644 --- a/src/backend/Board.java +++ b/src/backend/Board.java @@ -157,7 +157,7 @@ public class Board { // user clicks on the board public void userTouch(int x, int y) { - if (selectedX == -1 && selectedY == -1) { // ******REVIEW****** Faudrait pas mettre || ? + if (selectedX == -1 && selectedY == -1) { // This condition is only possible at the very start of the game // check if the position is empty and the color if (board[x][y] != null && board[x][y].isWhite() == isTurnWhite()) { // select it as active location @@ -167,7 +167,7 @@ public class Board { } } else { if (x == selectedX && y == selectedY) { - // unselect it + // unselect it if the destination is unvalid (not highlighted) selectedX = -1; selectedY = -1; highlightedPositions.clear(); From b18bd1c46bebd48a5fba7ef52a125fddddc9e1fd Mon Sep 17 00:00:00 2001 From: lrave Date: Tue, 6 May 2025 14:50:07 +0200 Subject: [PATCH 6/6] clear console comment --- src/backend/Board.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/Board.java b/src/backend/Board.java index 24cc72b..d21b0ac 100644 --- a/src/backend/Board.java +++ b/src/backend/Board.java @@ -91,7 +91,7 @@ public class Board { } } - private void clearConsole() { + private void clearConsole() { // ***************CONSOLE for (int i = 0; i < 50; i++) { System.out.println(); // Print 50 empty lines to "clear" the console }