39 lines
1.0 KiB
Java
39 lines
1.0 KiB
Java
import java.util.*;
|
|
import javax.swing.ImageIcon;
|
|
|
|
public class Knight extends Piece {
|
|
static int[] xDir = {-1, -2, -2, -1, 1, 2, 2, 1};
|
|
static int[] yDir = {-2, -1, 1, 2, 2, 1, -1, -2};
|
|
|
|
public Knight(int x, int y, String color) {
|
|
super(x, y, color, new ImageIcon("sprites/" + color + "/knight.png").getImage());
|
|
}
|
|
|
|
public Piece copy() {
|
|
Piece newP = new Knight(this.pos.x, this.pos.y, this.color);
|
|
return newP;
|
|
}
|
|
|
|
public ArrayList<Position> getPseudoLegalMoves(Board board) {
|
|
ArrayList<Position> positions = new ArrayList<Position>();
|
|
|
|
for (int i = 0; i < xDir.length; i++) {
|
|
Position test = new Position(pos.x + xDir[i], pos.y + yDir[i]);
|
|
if (!Board.inBounds(test)) continue;
|
|
if (board.isOpen(test)) {
|
|
positions.add(test);
|
|
continue;
|
|
}
|
|
if (!board.getPiece(test).colorMatches(this)) {
|
|
positions.add(test);
|
|
}
|
|
}
|
|
|
|
return positions;
|
|
}
|
|
|
|
public ArrayList<Position> getLegalMoves(Board board) {
|
|
return null;
|
|
}
|
|
}
|