remove "instanceof Pawn"

This commit is contained in:
2025-04-05 10:26:47 +02:00
parent 9af06e36f8
commit 8c2c6946d7
5 changed files with 66 additions and 6 deletions

View File

@@ -12,6 +12,7 @@ import chess.model.pieces.Knight;
import chess.model.pieces.Pawn;
import chess.model.pieces.Queen;
import chess.model.pieces.Rook;
import chess.model.visitor.PawnIdentifier;
public class PromoteCommand extends PlayerCommand {
@@ -39,7 +40,7 @@ public class PromoteCommand extends PlayerCommand {
return CommandResult.NotAllowed;
Piece pawn = board.pieceAt(this.pieceCoords);
if (pawn == null || !(pawn instanceof Pawn))
if (!new PawnIdentifier(game.getPlayerTurn()).isPawn(pawn))
return CommandResult.NotAllowed;
int destY = this.pieceCoords.getY();