refactored pawn movement + implemented knight movement
This commit is contained in:
15
Knight.java
15
Knight.java
@@ -12,10 +12,17 @@ public class Knight extends Piece {
|
||||
public ArrayList<Position> getLegalMoves(Board board) {
|
||||
ArrayList<Position> positions = new ArrayList<Position>();
|
||||
|
||||
for (int i : xDir) {
|
||||
for (int j : yDir) {
|
||||
Position test = new Position(pos.x + i, pos.y + j);
|
||||
if (!Board.inBounds(test)) continue;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user