board
This commit is contained in:
parent
4658af653d
commit
24df1d6565
|
|
@ -267,14 +267,47 @@ public class Board {
|
||||||
return x >= 0 && y >= 0 && x < colNum && y < lineNum;
|
return x >= 0 && y >= 0 && x < colNum && y < lineNum;
|
||||||
}
|
}
|
||||||
|
|
||||||
// other methods not changed
|
// PART3
|
||||||
public String[] toFileRep() {
|
public String[] toFileRep() {
|
||||||
//TODO
|
String[] result = new String[lineNum + 1]; // One line per row + 1 for turn
|
||||||
return null;
|
for (int y = 0; y < lineNum; y++) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for (int x = 0; x < colNum; x++) {
|
||||||
|
if (x > 0) sb.append(",");
|
||||||
|
Piece piece = board[y][x];
|
||||||
|
if (piece != null) {
|
||||||
|
sb.append(piece.isWhite() ? "W" : "B");
|
||||||
|
sb.append(piece.getType().getSummary()); // Ensure this returns K/Q/R/N/B/P
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result[y] = sb.toString();
|
||||||
|
}
|
||||||
|
result[lineNum] = isWhiteTurn ? "W" : "B";
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Board(String[] array) {
|
public Board(String[] array) {
|
||||||
//TODO
|
this.colNum = 8;
|
||||||
|
this.lineNum = 8;
|
||||||
|
this.board = new Piece[lineNum][colNum];
|
||||||
|
|
||||||
|
for (int y = 0; y < lineNum; y++) {
|
||||||
|
String[] tokens = array[y].split(",", -1);
|
||||||
|
for (int x = 0; x < colNum; x++) {
|
||||||
|
String token = tokens[x].trim();
|
||||||
|
if (token.length() == 2) {
|
||||||
|
boolean isWhite = token.charAt(0) == 'W';
|
||||||
|
char typeChar = token.charAt(1);
|
||||||
|
PieceType type = PieceType.fromSummary(typeChar); // You must implement this method
|
||||||
|
board[y][x] = new Piece(x, y, type, isWhite);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.isWhiteTurn = array[lineNum].equalsIgnoreCase("W");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void undoLastMove() {
|
public void undoLastMove() {
|
||||||
//TODO
|
//TODO
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue