remove PawnIdentifier
This commit is contained in:
@@ -9,9 +9,9 @@ import chess.model.Game;
|
|||||||
import chess.model.Piece;
|
import chess.model.Piece;
|
||||||
import chess.model.pieces.Bishop;
|
import chess.model.pieces.Bishop;
|
||||||
import chess.model.pieces.Knight;
|
import chess.model.pieces.Knight;
|
||||||
|
import chess.model.pieces.Pawn;
|
||||||
import chess.model.pieces.Queen;
|
import chess.model.pieces.Queen;
|
||||||
import chess.model.pieces.Rook;
|
import chess.model.pieces.Rook;
|
||||||
import chess.model.visitor.PawnIdentifier;
|
|
||||||
|
|
||||||
public class PromoteCommand extends PlayerCommand {
|
public class PromoteCommand extends PlayerCommand {
|
||||||
|
|
||||||
@@ -43,7 +43,7 @@ public class PromoteCommand extends PlayerCommand {
|
|||||||
return CommandResult.NotAllowed;
|
return CommandResult.NotAllowed;
|
||||||
|
|
||||||
Piece pawn = board.pieceAt(this.pieceCoords);
|
Piece pawn = board.pieceAt(this.pieceCoords);
|
||||||
if (!new PawnIdentifier(game.getPlayerTurn()).isPawn(pawn))
|
if (!(pawn instanceof Pawn))
|
||||||
return CommandResult.NotAllowed;
|
return CommandResult.NotAllowed;
|
||||||
|
|
||||||
int destY = this.pieceCoords.getY();
|
int destY = this.pieceCoords.getY();
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import java.util.List;
|
|||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import chess.model.pieces.King;
|
import chess.model.pieces.King;
|
||||||
import chess.model.visitor.PawnIdentifier;
|
import chess.model.pieces.Pawn;
|
||||||
import chess.model.visitor.PiecePathChecker;
|
import chess.model.visitor.PiecePathChecker;
|
||||||
|
|
||||||
public class ChessBoard {
|
public class ChessBoard {
|
||||||
@@ -296,13 +296,12 @@ public class ChessBoard {
|
|||||||
*/
|
*/
|
||||||
private Coordinate pawnPromotePosition(Color color) {
|
private Coordinate pawnPromotePosition(Color color) {
|
||||||
int enemyLineY = color == Color.White ? 0 : 7;
|
int enemyLineY = color == Color.White ? 0 : 7;
|
||||||
PawnIdentifier identifier = new PawnIdentifier(color);
|
|
||||||
|
|
||||||
for (int x = 0; x < Coordinate.VALUE_MAX; x++) {
|
for (int x = 0; x < Coordinate.VALUE_MAX; x++) {
|
||||||
Coordinate pieceCoords = new Coordinate(x, enemyLineY);
|
Coordinate pieceCoords = new Coordinate(x, enemyLineY);
|
||||||
Piece piece = pieceAt(pieceCoords);
|
Piece piece = pieceAt(pieceCoords);
|
||||||
|
|
||||||
if (identifier.isPawn(piece))
|
if (piece instanceof Pawn)
|
||||||
return pieceCoords;
|
return pieceCoords;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,52 +0,0 @@
|
|||||||
package chess.model.visitor;
|
|
||||||
|
|
||||||
import chess.model.Color;
|
|
||||||
import chess.model.Piece;
|
|
||||||
import chess.model.PieceVisitor;
|
|
||||||
import chess.model.pieces.*;
|
|
||||||
|
|
||||||
public class PawnIdentifier implements PieceVisitor<Boolean> {
|
|
||||||
|
|
||||||
private final Color color;
|
|
||||||
|
|
||||||
public PawnIdentifier(Color color) {
|
|
||||||
this.color = color;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isPawn(Piece piece) {
|
|
||||||
if (piece == null)
|
|
||||||
return false;
|
|
||||||
return visit(piece);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Boolean visitPiece(Bishop bishop) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Boolean visitPiece(King king) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Boolean visitPiece(Knight knight) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Boolean visitPiece(Pawn pawn) {
|
|
||||||
return pawn.getColor() == color;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Boolean visitPiece(Queen queen) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Boolean visitPiece(Rook rook) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -104,10 +104,11 @@ public class PiecePathChecker implements PieceVisitor<Boolean> {
|
|||||||
Coordinate middle = lastMove.getMiddle();
|
Coordinate middle = lastMove.getMiddle();
|
||||||
|
|
||||||
if (middle.equals(this.move.getFinish())
|
if (middle.equals(this.move.getFinish())
|
||||||
&& new PawnIdentifier(pieceToEat.getColor()).isPawn(pieceToEat)) {
|
&& pieceToEat instanceof Pawn) {
|
||||||
this.move.setDeadPieceCoords(lastMove.getFinish());
|
this.move.setDeadPieceCoords(lastMove.getFinish());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user