king, copy board logic, getPseudoMoves
This commit is contained in:
23
Piece.java
23
Piece.java
@@ -18,7 +18,30 @@ public abstract class Piece {
|
||||
|
||||
public abstract ArrayList<Position> getLegalMoves(Board board);
|
||||
|
||||
public abstract ArrayList<Position> getPseudoLegalMoves(Board board);
|
||||
|
||||
public abstract Piece copy();
|
||||
|
||||
public boolean colorMatches(Piece p) {
|
||||
return this.color.equals(p.color);
|
||||
}
|
||||
|
||||
public ArrayList<Position> slide(Board board, int dx, int dy) {
|
||||
ArrayList<Position> positions = new ArrayList<>();
|
||||
int step = 1;
|
||||
while (true) {
|
||||
Position test = new Position(pos.x + step * dx, pos.y + step * dy);
|
||||
if (!Board.inBounds(test)) break;
|
||||
if (board.isOpen(test)) {
|
||||
positions.add(test);
|
||||
} else if (board.getPiece(test).colorMatches(this)) {
|
||||
break;
|
||||
} else {
|
||||
positions.add(test);
|
||||
break;
|
||||
}
|
||||
step++;
|
||||
}
|
||||
return positions;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user