refactored pawn movement + implemented knight movement

This commit is contained in:
CT
2026-04-23 16:18:28 -05:00
parent 6e6c222d57
commit ce61482b9e
4 changed files with 34 additions and 18 deletions

View File

@@ -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);
}
}