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

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