This commit is contained in:
LENG Sidenn 2025-05-06 14:35:57 +02:00
commit 5e8632b7e3
1 changed files with 31 additions and 3 deletions

View File

@ -39,8 +39,16 @@ public class Board {
}
public void setPiece(boolean isWhite, PieceType type, int x, int y) {
//TODO
// Ensure coordinates are inside the board boundaries
// if (x < 0 || x >= width || y < 0 || y >= height) {
// System.out.println("Invalid coordinates: (" + x + ", " + y + ")");
// return;
// }
// Create and place the new piece
board[x][y] = new Piece(isWhite, type, x, y);
}
public void populateBoard() {
/*
@ -84,8 +92,28 @@ public class Board {
}
public String toString() {
//TODO
return "";
StringBuilder sb = new StringBuilder();
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
Piece piece = board[x][y];
if (piece == null) {
sb.append(" ");
} else {
sb.append(piece.isWhite() ? "W" : "B");
switch (piece.getType()) {
case Rook: sb.append("R"); break;
case Knight: sb.append("N"); break;
case Bishop: sb.append("B"); break;
case Queen: sb.append("Q"); break;
case King: sb.append("K"); break;
case Pawn: sb.append("P"); break;
}
}
if (x < width - 1) sb.append(",");
}
sb.append("\n");
}
return sb.toString();
}
public ArrayList<Piece> getPieces() {