idk
This commit is contained in:
17
King.java
17
King.java
@@ -35,17 +35,28 @@ public class King extends Piece {
|
||||
}
|
||||
|
||||
public ArrayList<Position> getLegalMoves(Board board) {
|
||||
return null;
|
||||
ArrayList<Position> positions = getPseudoLegalMoves(board);
|
||||
for (Position p : new ArrayList<>(positions)) {
|
||||
Piece tempPiece = board.getPiece(p);
|
||||
board.setPiece(pos, tempPiece);
|
||||
board.setPiece(p, this);
|
||||
if (inCheck(board, p)) {
|
||||
positions.remove(p);
|
||||
}
|
||||
board.setPiece(p, tempPiece);
|
||||
board.setPiece(pos, this);
|
||||
}
|
||||
return positions;
|
||||
}
|
||||
|
||||
public boolean inCheck(Board board) {
|
||||
public boolean inCheck(Board board, Position pos) {
|
||||
for (Piece[] pieces : board.board) {
|
||||
for (Piece p : pieces) {
|
||||
if (p == null) continue;
|
||||
if (!p.colorMatches(this) && !(p instanceof King)) {
|
||||
ArrayList<Position> ar = p.getLegalMoves(board);
|
||||
for (Position posi : ar) {
|
||||
if (this.pos.equals(posi)) return true;
|
||||
if (pos.equals(posi)) return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user