remove game signals
This commit is contained in:
@@ -2,7 +2,6 @@ package chess.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
|
||||
import chess.model.visitor.KingIdentifier;
|
||||
import chess.model.visitor.PiecePathChecker;
|
||||
@@ -26,8 +25,8 @@ public class ChessBoard {
|
||||
}
|
||||
|
||||
private final Cell[][] cells;
|
||||
private final Stack<Move> moves;
|
||||
private final Stack<Piece> ejectedPieces;
|
||||
private Move lastMove;
|
||||
private Piece lastEjectedPiece;
|
||||
|
||||
public ChessBoard() {
|
||||
this.cells = new Cell[Coordinate.VALUE_MAX][Coordinate.VALUE_MAX];
|
||||
@@ -36,43 +35,41 @@ public class ChessBoard {
|
||||
this.cells[i][j] = new Cell();
|
||||
}
|
||||
}
|
||||
this.moves = new Stack<>();
|
||||
this.ejectedPieces = new Stack<>();
|
||||
this.lastMove = null;
|
||||
this.lastEjectedPiece = null;
|
||||
}
|
||||
|
||||
public void applyMove(Move move) {
|
||||
assert (move.isValid());
|
||||
assert move.isValid() : "Invalid move !";
|
||||
Piece deadPiece = pieceAt(move.getFinish());
|
||||
if (deadPiece != null) {
|
||||
deadPiece.eject(this.moves.size());
|
||||
this.ejectedPieces.add(deadPiece);
|
||||
this.lastEjectedPiece = deadPiece;
|
||||
} else {
|
||||
this.lastEjectedPiece = null;
|
||||
}
|
||||
Piece movingPiece = pieceAt(move.getStart());
|
||||
pieceComes(movingPiece, move.getFinish());
|
||||
pieceLeaves(move.getStart());
|
||||
movingPiece.move();
|
||||
this.moves.add(move);
|
||||
this.lastMove = move;
|
||||
}
|
||||
|
||||
public void undoLastMove() {
|
||||
assert !this.moves.empty() : "Can't undo at the beginning!";
|
||||
assert this.lastMove != null: "Can't undo at the beginning!";
|
||||
|
||||
Move move = this.moves.pop();
|
||||
Move move = this.lastMove;
|
||||
|
||||
Piece movingPiece = pieceAt(move.getFinish());
|
||||
pieceComes(movingPiece, move.getStart());
|
||||
pieceLeaves(move.getFinish());
|
||||
movingPiece.unMove();
|
||||
|
||||
if (this.ejectedPieces.empty())
|
||||
if (this.lastEjectedPiece == null)
|
||||
return;
|
||||
|
||||
Piece piece = this.ejectedPieces.lastElement();
|
||||
if (piece.getEjectedMoveNumber() != this.moves.size())
|
||||
return;
|
||||
Piece piece = this.lastEjectedPiece;
|
||||
|
||||
pieceComes(piece, move.getFinish());
|
||||
piece.eject(-1);
|
||||
}
|
||||
|
||||
public boolean isCellEmpty(Coordinate coordinate) {
|
||||
|
||||
Reference in New Issue
Block a user