trial I think it didn't commit
This commit is contained in:
parent
b12735869a
commit
c03ff7d03e
|
|
@ -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<Position> getValidMoves(Piece p) {
|
||||
private ArrayList<Position> findMoves(Piece p) {
|
||||
ArrayList<Position> 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<Position> moves, int x, int y, boolean isWhite, int dx, int dy) {
|
||||
private void extend(ArrayList<Position> 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) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue