Movement restriction for Knight

main
jylkyle 2 years ago
parent 419d33bc88
commit 9063667ca5

@ -12,11 +12,32 @@ public class Pawn extends Piece {
public ArrayList<Move> getPossibleMoves(BoardCoordinate position, Board board) { public ArrayList<Move> getPossibleMoves(BoardCoordinate position, Board board) {
ArrayList<Move> possibleMoves = new ArrayList<>(); ArrayList<Move> possibleMoves = new ArrayList<>();
if (this.black) { if (this.black) {
if (board.get(position.x, position.y + 1) == null) {
possibleMoves.add(new Move(position, new BoardCoordinate(position.x, position.y + 1))); possibleMoves.add(new Move(position, new BoardCoordinate(position.x, position.y + 1)));
if (!moved && board.get(position.x, position.y + 1) == null) possibleMoves.add(new Move(position, new BoardCoordinate(position.x, position.y + 2))); if (!moved) {
possibleMoves.add(new Move(position, new BoardCoordinate(position.x, position.y + 2)));
}
}
if (board.get(position.x - 1, position.y + 1) != null) {
possibleMoves.add(new Move(position, new BoardCoordinate(position.x - 1,position.y + 1)));
}
if (board.get(position.x + 1, position.y + 1) != null) {
possibleMoves.add(new Move(position, new BoardCoordinate(position.x + 1,position.y + 1)));
}
} else { } else {
if (board.get(position.x, position.y - 1) == null) {
possibleMoves.add(new Move(position, new BoardCoordinate(position.x, position.y - 1))); possibleMoves.add(new Move(position, new BoardCoordinate(position.x, position.y - 1)));
if (!moved && board.get(position.x, position.y - 1) == null) possibleMoves.add(new Move(position, new BoardCoordinate(position.x, position.y - 2))); if (!moved) {
possibleMoves.add(new Move(position, new BoardCoordinate(position.x, position.y - 2)));
}
}
if (board.get(position.x - 1, position.y - 1) != null) {
possibleMoves.add(new Move(position, new BoardCoordinate(position.x - 1,position.y - 1)));
}
if (board.get(position.x + 1, position.y - 1) != null) {
possibleMoves.add(new Move(position, new BoardCoordinate(position.x + 1,position.y - 1)));
}
} }
return possibleMoves; return possibleMoves;
} }