added toString

This commit is contained in:
Jérôme BEDIER 2025-05-06 14:15:37 +02:00
parent b2e94360a1
commit 2b5e128809
1 changed files with 22 additions and 2 deletions

View File

@ -76,8 +76,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() {