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 ArrayList getLegalMoves(Board board) { ArrayList positions = new ArrayList(); for (int i = 0; i < xDir.length; i++) { int xPlus = xDir[i]; int yPlus = yDir[i]; Position test = new Position(pos.x + xPlus, pos.y + yPlus); if (!Board.inBounds(test)) continue; if (board.isOpen(test)) { positions.add(test); continue; } if (!board.getPiece(test).colorMatches(this)) { positions.add(test); } } return positions; } }