now able to print out the current state of the chess board

This commit is contained in:
Tikea TE 2025-04-10 11:54:37 +02:00
parent c280b179c4
commit af2d8d7c4e
1 changed files with 23 additions and 3 deletions

View File

@ -86,8 +86,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 found = null;
for (Piece p : Pieces) {
if (p.getX() == x && p.getY() == y) {
found = p;
break;
}
}
if (found != null) {
String color = found.isWhite() ? "W" : "B";
sb.append(color).append(found.getType().getSummary()).append(" ");
} else {
sb.append(".. ");
}
}
sb.append("\n");
}
return sb.toString();
}