From c03ff7d03e9dff69b5981c19d3d83d9577ea226b Mon Sep 17 00:00:00 2001 From: Juliette Date: Tue, 13 May 2025 19:25:35 +0200 Subject: [PATCH] trial I think it didn't commit --- src/backend/Board.java | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/backend/Board.java b/src/backend/Board.java index a63a471..8c68729 100644 --- a/src/backend/Board.java +++ b/src/backend/Board.java @@ -167,7 +167,7 @@ public class Board { selectedY = y; highlight.clear(); - highlight.addAll(getValidMoves(p)); + highlight.addAll(findMoves(p)); } else { selectedX = -1; selectedY = -1; @@ -209,7 +209,7 @@ public class Board { //TODO } - private ArrayList getValidMoves(Piece p) { + private ArrayList findMoves(Piece p) { ArrayList moves = new ArrayList<>(); int x = p.getX(); @@ -260,28 +260,28 @@ public class Board { } if (p.getType() == PieceType.Rook) { - addMovesInLine(moves, x, y, isWhite, 1, 0); - addMovesInLine(moves, x, y, isWhite, -1, 0); - addMovesInLine(moves, x, y, isWhite, 0, 1); - addMovesInLine(moves, x, y, isWhite, 0, -1); + extend(moves, x, y, isWhite, 1, 0); + extend(moves, x, y, isWhite, -1, 0); + extend(moves, x, y, isWhite, 0, 1); + extend(moves, x, y, isWhite, 0, -1); } if (p.getType() == PieceType.Bishop) { - addMovesInLine(moves, x, y, isWhite, 1, 1); - addMovesInLine(moves, x, y, isWhite, -1, 1); - addMovesInLine(moves, x, y, isWhite, 1, -1); - addMovesInLine(moves, x, y, isWhite, -1, -1); + extend(moves, x, y, isWhite, 1, 1); + extend(moves, x, y, isWhite, -1, 1); + extend(moves, x, y, isWhite, 1, -1); + extend(moves, x, y, isWhite, -1, -1); } if (p.getType() == PieceType.Queen) { - addMovesInLine(moves, x, y, isWhite, 1, 0); - addMovesInLine(moves, x, y, isWhite, -1, 0); - addMovesInLine(moves, x, y, isWhite, 0, 1); - addMovesInLine(moves, x, y, isWhite, 0, -1); - addMovesInLine(moves, x, y, isWhite, 1, 1); - addMovesInLine(moves, x, y, isWhite, -1, 1); - addMovesInLine(moves, x, y, isWhite, 1, -1); - addMovesInLine(moves, x, y, isWhite, -1, -1); + extend(moves, x, y, isWhite, 1, 0); + extend(moves, x, y, isWhite, -1, 0); + extend(moves, x, y, isWhite, 0, 1); + extend(moves, x, y, isWhite, 0, -1); + extend(moves, x, y, isWhite, 1, 1); + extend(moves, x, y, isWhite, -1, 1); + extend(moves, x, y, isWhite, 1, -1); + extend(moves, x, y, isWhite, -1, -1); } if (p.getType() == PieceType.King) { @@ -302,7 +302,7 @@ public class Board { return moves; } - private void addMovesInLine(ArrayList moves, int x, int y, boolean isWhite, int dx, int dy) { + private void extend(ArrayList moves, int x, int y, boolean isWhite, int dx, int dy) { int nx = x + dx; int ny = y + dy; while (nx >= 0 && nx < colNum && ny >= 0 && ny < lineNum) {