setting up
This commit is contained in:
parent
66b6416e6f
commit
0c6c2ca9c1
|
|
@ -263,8 +263,16 @@ public class Board {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void undoLastMove() {
|
public void undoLastMove() {
|
||||||
//TODO
|
ArrayList<Move> moveHistory = new ArrayList<>();
|
||||||
|
if (moveHistory.isEmpty()) {
|
||||||
|
Move lastMove = moveHistory.remove(moveHistory.size()-1);
|
||||||
|
cells[lastMove.getFromX()][lastMove.getFromY()] = lastMove.getPiece();
|
||||||
|
cells[lastMove.getToX()][lastMove.getToY()] = lastMove.getCapturedPiece();;
|
||||||
|
|
||||||
|
if (lastMove.getCapturedPiece()!=null) {
|
||||||
|
//cells.add(lastMove.getCapturedPiece());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Board(Board other) {
|
public Board(Board other) {
|
||||||
|
|
@ -285,8 +293,23 @@ public class Board {
|
||||||
|
|
||||||
|
|
||||||
public void playMove(Move move) {
|
public void playMove(Move move) {
|
||||||
//TODO
|
|
||||||
|
int fromX = move.getFromX();
|
||||||
|
int fromY = move.getFromY();
|
||||||
|
int toX = move.getToX();
|
||||||
|
int toY = move.getToY();
|
||||||
|
|
||||||
|
Piece movingPiece = cells[fromX][fromY];
|
||||||
|
if (movingPiece == null) {
|
||||||
|
System.err.println("No piece at source position.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
cells[toX][toY] = new Piece(movingPiece.getType(), movingPiece.isWhite(), toX, toY);
|
||||||
|
cells[fromX][fromY] = null;
|
||||||
|
|
||||||
|
System.out.println("Moved " + movingPiece.getType() + " from (" + fromX + "," + fromY + ") to (" + toX + "," + toY + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue