iaaaaaaaaaaaaaa
This commit is contained in:
@@ -137,21 +137,54 @@ public class ChessBoard {
|
||||
}
|
||||
|
||||
public boolean hasAllowedMoves(Color player) {
|
||||
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)
|
||||
// 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)
|
||||
// continue;
|
||||
|
||||
// if (attackPiece.getColor() != player)
|
||||
// continue;
|
||||
|
||||
// if (!getAllowedMoves(attackCoords).isEmpty())
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
return !getAllowedMoves(player).isEmpty();
|
||||
}
|
||||
|
||||
public List<Move> getAllowedMoves(Color player) {
|
||||
List<Move> result = new ArrayList<>();
|
||||
|
||||
for (int x = 0; x < Coordinate.VALUE_MAX; x++) {
|
||||
for (int y = 0; y < Coordinate.VALUE_MAX; y++) {
|
||||
|
||||
Coordinate start = new Coordinate(x, y);
|
||||
|
||||
Piece piece = pieceAt(start);
|
||||
if (piece == null || piece.getColor() != player)
|
||||
continue;
|
||||
|
||||
if (attackPiece.getColor() != player)
|
||||
continue;
|
||||
for (int i = 0; i < Coordinate.VALUE_MAX; i++) {
|
||||
for (int j = 0; j < Coordinate.VALUE_MAX; j++) {
|
||||
Coordinate destination = new Coordinate(i, j);
|
||||
Move move = new Move(start, destination);
|
||||
|
||||
if (!getAllowedMoves(attackCoords).isEmpty())
|
||||
return true;
|
||||
PiecePathChecker piecePathChecker = new PiecePathChecker(this,
|
||||
move);
|
||||
if (!piecePathChecker.isValid())
|
||||
continue;
|
||||
|
||||
applyMove(move);
|
||||
if (!isKingInCheck(player))
|
||||
result.add(move);
|
||||
undoLastMove();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<Coordinate> getAllowedMoves(Coordinate pieceCoords) {
|
||||
@@ -256,7 +289,6 @@ public class ChessBoard {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public Move getLastMove() {
|
||||
return this.lastMove;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user