diff --git a/src/backend/Board.java b/src/backend/Board.java index d973aa9..d3310ab 100644 --- a/src/backend/Board.java +++ b/src/backend/Board.java @@ -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 getPieces() {