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

@@ -1,6 +1,6 @@
package chess.model;
import chess.model.pieces.Pawn;
import chess.model.visitor.PawnIdentifier;
public class Game {
private final ChessBoard board;
@@ -66,15 +66,15 @@ public class Game {
*/
private Coordinate pawnPromotePosition(Color color) {
int enemyLineY = color == Color.White ? 0 : 7;
PawnIdentifier identifier = new PawnIdentifier(color);
for (int x = 0; x < Coordinate.VALUE_MAX; x++) {
Coordinate pieceCoords = new Coordinate(x, enemyLineY);
Piece piece = getBoard().pieceAt(pieceCoords);
if (piece == null || !(piece instanceof Pawn) || piece.getColor() != color)
continue;
if (identifier.isPawn(piece))
return pieceCoords;
return pieceCoords;
}
return null;