les pions peuvent manger
This commit is contained in:
parent
b1c65c9612
commit
04e8856ab0
|
|
@ -333,16 +333,65 @@ public class Board {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Board(Board board) {
|
public Board(Board board) {
|
||||||
//TODO
|
this.width = board.getWidth();
|
||||||
|
this.height = board.getHeight();
|
||||||
|
this.turnNumber = board.getTurnNumber();
|
||||||
|
this.turnWhite = board.isTurnWhite();
|
||||||
|
|
||||||
|
this.pieces = new ArrayList<>();
|
||||||
|
for (Piece p : board.getPieces()) {
|
||||||
|
// Create a new Piece with the same values (deep copy)
|
||||||
|
Piece copy = new Piece(p.isWhite(), p.getType(), p.getX(), p.getY());
|
||||||
|
this.pieces.add(copy);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Optional: copy selected square if needed
|
||||||
|
this.selectedX = board.selectedX;
|
||||||
|
this.selectedY = board.selectedY;
|
||||||
|
|
||||||
|
// Optional: copy highlighted squares
|
||||||
|
this.highlightedSquares = new ArrayList<>();
|
||||||
|
for (int[] square : board.highlightedSquares) {
|
||||||
|
this.highlightedSquares.add(new int[]{square[0], square[1]});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Optional: copy move history (use only if Move has a proper copy strategy)
|
||||||
|
this.moveHistory = new ArrayList<>(board.moveHistory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void playMove(Move move) {
|
public void playMove(Move move) {
|
||||||
//TODO
|
// Get the piece to move
|
||||||
|
Piece pieceToMove = getPieceAt(move.getFromX(), move.getFromY());
|
||||||
|
if (pieceToMove == null) return; // Invalid move, nothing to move
|
||||||
|
|
||||||
|
// Capture if there's a piece at the destination
|
||||||
|
Piece captured = getPieceAt(move.getToX(), move.getToY());
|
||||||
|
if (captured != null) {
|
||||||
|
pieces.remove(captured);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove the original piece
|
||||||
|
pieces.remove(pieceToMove);
|
||||||
|
|
||||||
|
// Add the moved piece at new location
|
||||||
|
setPiece(move.isWhite(), move.getType(), move.getToX(), move.getToY());
|
||||||
|
|
||||||
|
// Save move to history
|
||||||
|
moveHistory.add(move);
|
||||||
|
|
||||||
|
// Update turn
|
||||||
|
turnNumber++;
|
||||||
|
turnWhite = !turnWhite;
|
||||||
|
|
||||||
|
// Clear selection and highlights (optional safety)
|
||||||
|
selectedX = null;
|
||||||
|
selectedY = null;
|
||||||
|
highlightedSquares.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private Piece getPieceAt(int x, int y) {
|
private Piece getPieceAt(int x, int y) {
|
||||||
for (Piece p : pieces) {
|
for (Piece p : pieces) {
|
||||||
if (p.getX() == x && p.getY() == y) {
|
if (p.getX() == x && p.getY() == y) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue