Change in the function to display the color of the pieces on the console
This commit is contained in:
parent
014faea8ca
commit
ad91fec269
|
|
@ -432,36 +432,42 @@ public class Board {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String[] toFileRep() {
|
public String toString() {
|
||||||
String[] output = new String[height + 2];
|
StringBuilder sb = new StringBuilder();
|
||||||
StringBuilder top = new StringBuilder(" ");
|
|
||||||
|
// 1) File letters
|
||||||
|
sb.append(" ");
|
||||||
for (int x = 0; x < width; x++) {
|
for (int x = 0; x < width; x++) {
|
||||||
if (x > 0) top.append(" ");
|
char fileLetter = (char)('A' + x);
|
||||||
top.append((char)('A' + x));
|
sb.append(" ").append(fileLetter);
|
||||||
}
|
}
|
||||||
output[0] = top.toString();
|
sb.append("\n");
|
||||||
|
|
||||||
|
// 2) Ranks with pieces
|
||||||
for (int y = 0; y < height; y++) {
|
for (int y = 0; y < height; y++) {
|
||||||
int rank = height - y;
|
int rank = height - y;
|
||||||
StringBuilder row = new StringBuilder();
|
sb.append(rank).append(" ");
|
||||||
row.append(rank).append(" ");
|
|
||||||
for (int x = 0; x < width; x++) {
|
for (int x = 0; x < width; x++) {
|
||||||
if (x > 0) row.append(" ");
|
if (x > 0) sb.append(" ");
|
||||||
Piece p = getPieceAt(x, y);
|
Piece p = getPieceAt(x, y);
|
||||||
if (p == null) {
|
if (p == null) {
|
||||||
row.append(".");
|
sb.append("..");
|
||||||
} else {
|
} else {
|
||||||
char c = p.getType().getSummary();
|
char colorChar = p.isWhite() ? 'w' : 'b';
|
||||||
row.append(p.isWhite() ? Character.toUpperCase(c) : Character.toLowerCase(c));
|
char typeChar = Character.toLowerCase(p.getType().getSummary()); // standardized as lowercase
|
||||||
|
sb.append(colorChar).append(typeChar);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
output[y + 1] = row.toString();
|
sb.append("\n");
|
||||||
}
|
}
|
||||||
output[height + 1] = "Turn: " + (turnIsWhite ? "White" : "Black");
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// 3) Turn indicator
|
||||||
|
sb.append("Turn: ").append(turnIsWhite ? "White" : "Black");
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
// console print
|
||||||
public void printBoard() {
|
public void printBoard() {
|
||||||
for (String line : toFileRep()) System.out.println(line);
|
System.out.println(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void playMove(Move move) {
|
public void playMove(Move move) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue