add playMove

This commit is contained in:
Lymeng LY 2025-05-14 13:32:01 +02:00
parent 23758f25e5
commit acfd893135
1 changed files with 30 additions and 3 deletions

View File

@ -411,14 +411,41 @@ public class Board {
//Deep copy highlighted positions
this.highlightedPositions = new ArrayList<>();
for (int[] pos : highlightedPositions) {
//TO BE DONE
this.highlightedPositions.add(new int[]{pos[0], pos[1]});
}
//Deep copy of board and pieces
this.board = new Piece[col][line];
for (int y = 0; y < line; y++) {
for (int x = 0; x < col; x++) {
Piece p = board.board[y][x];
if (p != null) {
this.board[y][x] = new Piece(p.isWhite(), p.getType(), p.getX(), p.getY());
}
}
}
}
public void playMove(Move move) {
//TODO
//get current piece coordinate
int fromX = move.piece.getX();
int fromY = move.piece.getY();
//Remove the piece from the original position
board[fromX][fromY] = null;
//Update the internal position of the piece
move.piece.setX(move.toX);
move.piece.setY(move.toY);
//place the piece at the new position
board[move.toY][move.toX] = move.piece;
//end turn logic
this.turnWhite = !this.turnWhite;
this.turnNumber++;
//Clear selection/highlight
this.selectedPosition = null;
this.highlightedPositions.clear();
}