feat: pgn parser
This commit is contained in:
@@ -112,21 +112,33 @@ public class ChessBoard {
|
||||
}
|
||||
|
||||
public Coordinate findKing(Color color) {
|
||||
// KingIdentifier kingIdentifier = new KingIdentifier(color);
|
||||
// for (int i = 0; i < Coordinate.VALUE_MAX; i++) {
|
||||
// for (int j = 0; j < Coordinate.VALUE_MAX; j++) {
|
||||
// Coordinate coordinate = new Coordinate(i, j);
|
||||
// Piece piece = pieceAt(coordinate);
|
||||
// if (kingIdentifier.isKing(piece)) {
|
||||
// return coordinate;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// assert false : "No king found ?!";
|
||||
// return null;
|
||||
return kingPos[color.ordinal()];
|
||||
}
|
||||
|
||||
public List<Coordinate> getAllowedStarts(Coordinate finish, Color color) {
|
||||
List<Coordinate> starts = new ArrayList<>();
|
||||
for (int i = 0; i < Coordinate.VALUE_MAX; i++) {
|
||||
for (int j = 0; j < Coordinate.VALUE_MAX; j++) {
|
||||
Coordinate attackCoords = new Coordinate(i, j);
|
||||
Piece attackPiece = pieceAt(attackCoords);
|
||||
if (attackPiece == null || attackPiece.getColor() != color)
|
||||
continue;
|
||||
|
||||
Move move = new Move(attackCoords, finish);
|
||||
PiecePathChecker piecePathChecker = new PiecePathChecker(this,
|
||||
move);
|
||||
if (!piecePathChecker.isValid())
|
||||
continue;
|
||||
|
||||
applyMove(move);
|
||||
if (!isKingInCheck(color))
|
||||
starts.add(attackCoords);
|
||||
undoLastMove();
|
||||
}
|
||||
}
|
||||
return starts;
|
||||
}
|
||||
|
||||
public boolean isKingInCheck(Color color) {
|
||||
Coordinate kingPos = findKing(color);
|
||||
assert kingPos.isValid() : "King position is invalid!";
|
||||
|
||||
Reference in New Issue
Block a user