Compare commits
2 Commits
810a0f2159
...
11e6a94ed7
| Author | SHA1 | Date | |
|---|---|---|---|
| 11e6a94ed7 | |||
| c1bf9bcaf9 |
@@ -7,7 +7,7 @@ import chess.model.Coordinate;
|
|||||||
import chess.model.Game;
|
import chess.model.Game;
|
||||||
import chess.model.Move;
|
import chess.model.Move;
|
||||||
import chess.model.Piece;
|
import chess.model.Piece;
|
||||||
import chess.model.visitor.PiecePathChecker;
|
import chess.model.rules.PiecePathChecker;
|
||||||
|
|
||||||
public class MoveCommand extends PlayerCommand {
|
public class MoveCommand extends PlayerCommand {
|
||||||
|
|
||||||
|
|||||||
@@ -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,8 +5,8 @@ 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.rules.PiecePathChecker;
|
||||||
|
|
||||||
public class ChessBoard {
|
public class ChessBoard {
|
||||||
public static class Cell {
|
public static class Cell {
|
||||||
@@ -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,4 +1,4 @@
|
|||||||
package chess.model.visitor;
|
package chess.model.rules;
|
||||||
|
|
||||||
import chess.model.Coordinate;
|
import chess.model.Coordinate;
|
||||||
import chess.model.Direction;
|
import chess.model.Direction;
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package chess.model.visitor;
|
package chess.model.rules;
|
||||||
|
|
||||||
import chess.model.ChessBoard;
|
import chess.model.ChessBoard;
|
||||||
import chess.model.Color;
|
import chess.model.Color;
|
||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user