clean board

This commit is contained in:
User 2025-05-07 16:02:33 +02:00
parent 6beffc0b94
commit 93251fd76a
1 changed files with 106 additions and 112 deletions

View File

@ -9,73 +9,78 @@ public class Board {
private Piece[][] board; private Piece[][] board;
public Board(int colNum, int lineNum) { public Board(int colNum, int lineNum) {
//TODO
this.width = colNum; this.width = colNum;
this.height = lineNum; this.height = lineNum;
this.board= new Piece[width][height]; this.board = new Piece[width][height];
} }
public int getWidth() { public int getWidth() {
//TODO
return width; return width;
} }
public int getHeight() { public int getHeight() {
//TODO
return height; return height;
} }
public int getTurnNumber() { public int getTurnNumber() {
//TODO
return 0; return 0;
} }
public boolean isTurnWhite() { public boolean isTurnWhite() {
//TODO
return false; return false;
} }
public void setPiece(boolean isWhite, PieceType type, int x, int y) { public void setPiece(boolean isWhite, PieceType type, int x, int y) {
if (x >= 0 && x < width && y >= 0 && y < height) { if (x >= 0 && x < width && y >= 0 && y < height) {
board[y][x] = new Piece(x, y, isWhite, type); board[x][y] = new Piece(isWhite, type, x, y);
} }
} }
//TODO TEST
public void populateBoard() { public void populateBoard() {
cleanBoard(); cleanBoard();
// White pawns
for (int x = 0; x < 8; x++) { for (int x = 0; x < 8; x++) {
setPiece(true, PieceType.Pawn, x, 1); setPiece(true, PieceType.Pawn, x, 1);
} }
// Black pawns
for (int x = 0; x < 8; x++) { for (int x = 0; x < 8; x++) {
setPiece(false, PieceType.Pawn, x, 6); setPiece(false, PieceType.Pawn, x, 6);
} }
PieceType[] value = {PieceType.Rook, PieceType.Knight, PieceType.Bishop, PieceType.Queen, PieceType.King, PieceType.Bishop, PieceType.Knight, PieceType.Rook};
PieceType[] backRow = {
PieceType.Rook, PieceType.Knight, PieceType.Bishop,
PieceType.Queen, PieceType.King, PieceType.Bishop,
PieceType.Knight, PieceType.Rook
};
// White back row
for (int x = 0; x < 8; x++) { for (int x = 0; x < 8; x++) {
setPiece(true, value[x], x, 0); setPiece(true, backRow[x], x, 0);
} }
// Black back row
for (int x = 0; x < 8; x++) { for (int x = 0; x < 8; x++) {
setPiece(false, value[x], x, 7); setPiece(false, backRow[x], x, 7);
} } }
}
public void cleanBoard() { public void cleanBoard() {
//TODO for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
board[x][y] = null;
}
}
} }
public String toString() { public String toString() {
//TODO
return "board"; return "board";
} }
public ArrayList<Piece> getPieces() { public ArrayList<Piece> getPieces() {
ArrayList<Piece> pieces = new ArrayList<>(); ArrayList<Piece> pieces = new ArrayList<>();
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) { for (int x = 0; x < width; x++) {
if (board[y][x] != null) { for (int y = 0; y < height; y++) {
pieces.add(board[y][x]); if (board[x][y] != null) {
pieces.add(board[x][y]);
} }
} }
} }
@ -83,47 +88,36 @@ public class Board {
} }
public void userTouch(int x, int y) { public void userTouch(int x, int y) {
//TODO // TODO
} }
public boolean isSelected(int x, int y) { public boolean isSelected(int x, int y) {
//TODO
return false; return false;
} }
/* saving-loading feature :*/ /* saving-loading feature */
public String[] toFileRep() { public String[] toFileRep() {
//TODO
return null; return null;
} }
public Board(String[] array) { public Board(String[] array) {
//TODO // TODO
} }
/* The following methods require more work ! */ /* The following methods require more work */
public boolean isHighlighted(int x, int y) { public boolean isHighlighted(int x, int y) {
//TODO
return false; return false;
} }
public void undoLastMove() { public void undoLastMove() {
//TODO // TODO
} }
public Board(Board board) { public Board(Board board) {
//TODO // TODO
} }
public void playMove(Move move) { public void playMove(Move move) {
//TODO // TODO
} }
} }