diff --git a/src/Board.java b/src/Board.java index e04fd3b..2bf3dba 100644 --- a/src/Board.java +++ b/src/Board.java @@ -131,11 +131,9 @@ public class Board { // White pieces disappear if new move isn't created, don't know why Move copiedMove = new Move(new BoardCoordinate(move.from.x, move.from.y), new BoardCoordinate(move.to.x, move.to.y), get(move.to.x, move.to.y)); copiedMove.submove = move.submove; - copiedMove.isPromotion = move.isPromotion; moveHistory.add(copiedMove); // moveHistory.add(move); - Piece movedPiece = get(move.from); - set(move.to, move.isPromotion ? new Queen(movedPiece.black, panel) : movedPiece); + set(move.to, get(move.from)); set(move.from, null); move(move.submove); if (move.submove != null) moveHistory.pop(); @@ -150,8 +148,7 @@ public class Board { void undoMove(Move move) { if (move == null) return; - Piece movedPiece = get(move.to); - set(move.from, move.isPromotion ? new Pawn(movedPiece.black, panel) : movedPiece); + set(move.from, get(move.to)); set(move.to, move.captured); } diff --git a/src/Move.java b/src/Move.java index e45d013..13bbd1f 100644 --- a/src/Move.java +++ b/src/Move.java @@ -6,7 +6,6 @@ public class Move { public Piece captured; // e.g. castling, castle move. Done after. public Move submove; - public boolean isPromotion; public Move(BoardCoordinate from, BoardCoordinate to) { this.from = from; diff --git a/src/Pawn.java b/src/Pawn.java index 5058adc..513aad7 100644 --- a/src/Pawn.java +++ b/src/Pawn.java @@ -12,36 +12,11 @@ public class Pawn extends Piece { public ArrayList getPossibleMoves(BoardCoordinate position, Board board) { ArrayList possibleMoves = new ArrayList<>(); if (this.black) { - if (board.get(position.x, position.y + 1) == null) { - Move oneForward = new Move(position, new BoardCoordinate(position.x, position.y + 1)); - oneForward.isPromotion = position.y + 1 == Board.BOARD_SIZE - 1; - possibleMoves.add(oneForward); - if (!moved && board.get(position.x, position.y + 2) == null) { - possibleMoves.add(new Move(position, new BoardCoordinate(position.x, position.y + 2))); - } - } - if (board.get(position.x - 1, position.y + 1) != null) { - possibleMoves.add(new Move(position, new BoardCoordinate(position.x - 1,position.y + 1))); - } - if (board.get(position.x + 1, position.y + 1) != null) { - possibleMoves.add(new Move(position, new BoardCoordinate(position.x + 1,position.y + 1))); - } - + possibleMoves.add(new Move(position, new BoardCoordinate(position.x, position.y + 1))); + if (!moved && board.get(position.x, position.y + 1) == null) possibleMoves.add(new Move(position, new BoardCoordinate(position.x, position.y + 2))); } else { - if (board.get(position.x, position.y - 1) == null) { - Move oneForward = new Move(position, new BoardCoordinate(position.x, position.y - 1)); - oneForward.isPromotion = position.y - 1 == 0; - possibleMoves.add(oneForward); - if (!moved && board.get(position.x, position.y - 2) == null) { - possibleMoves.add(new Move(position, new BoardCoordinate(position.x, position.y - 2))); - } - } - if (board.get(position.x - 1, position.y - 1) != null) { - possibleMoves.add(new Move(position, new BoardCoordinate(position.x - 1,position.y - 1))); - } - if (board.get(position.x + 1, position.y - 1) != null) { - possibleMoves.add(new Move(position, new BoardCoordinate(position.x + 1,position.y - 1))); - } + possibleMoves.add(new Move(position, new BoardCoordinate(position.x, position.y - 1))); + if (!moved && board.get(position.x, position.y - 1) == null) possibleMoves.add(new Move(position, new BoardCoordinate(position.x, position.y - 2))); } return possibleMoves; }