This commit is contained in:
ricoc 2025-05-06 14:19:16 +02:00
commit b1916bd81f
1 changed files with 8 additions and 8 deletions

View File

@ -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<int[]> 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
}
@ -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);