Want to contribute? Fork me on Codeberg.org!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

26 lines
1.2 KiB

import java.awt.*;
import java.util.ArrayList;
public class Knight extends Piece {
public Knight(boolean black, DrawingPanel panel) {
super(black, panel, "black-knight.png", "white-knight.png");
}
public int getValue() {
return 3;
}
public ArrayList<Move> getPossibleMoves(BoardCoordinate position, Board board) {
ArrayList<Move> possibleMoves = new ArrayList<>();
possibleMoves.add(new Move(position, new BoardCoordinate(position.x - 2, position.y - 1)));
possibleMoves.add(new Move(position, new BoardCoordinate(position.x - 1, position.y - 2)));
possibleMoves.add(new Move(position, new BoardCoordinate(position.x + 1, position.y - 2)));
possibleMoves.add(new Move(position, new BoardCoordinate(position.x + 2, position.y - 1)));
possibleMoves.add(new Move(position, new BoardCoordinate(position.x + 2, position.y + 1)));
possibleMoves.add(new Move(position, new BoardCoordinate(position.x + 1, position.y + 2)));
possibleMoves.add(new Move(position, new BoardCoordinate(position.x - 1, position.y + 2)));
possibleMoves.add(new Move(position, new BoardCoordinate(position.x - 2, position.y + 1)));
return possibleMoves;
}
}