les pieces bougent !!!!!
This commit is contained in:
parent
04e8856ab0
commit
9e15058fb8
|
|
@ -432,8 +432,100 @@ private ArrayList<int[]> computeLegalMoves(Piece piece) {
|
|||
if (isEnemy(x + 1, nextY, piece.isWhite())) {
|
||||
moves.add(new int[]{x + 1, nextY});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (type == PieceType.Rook) {
|
||||
// Directions : haut, bas, gauche, droite
|
||||
int[][] directions = {{1,0},{-1,0},{0,1},{0,-1}};
|
||||
for (int[] dir : directions) {
|
||||
int nx = x + dir[0];
|
||||
int ny = y + dir[1];
|
||||
while (nx >= 0 && nx < width && ny >= 0 && ny < height) {
|
||||
if (isEmpty(nx, ny)) {
|
||||
moves.add(new int[]{nx, ny});
|
||||
} else {
|
||||
if (isEnemy(nx, ny, piece.isWhite())) {
|
||||
moves.add(new int[]{nx, ny});
|
||||
}
|
||||
break;
|
||||
}
|
||||
nx += dir[0];
|
||||
ny += dir[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (type == PieceType.Bishop) {
|
||||
// Directions : diagonales
|
||||
int[][] directions = {{1,1},{1,-1},{-1,1},{-1,-1}};
|
||||
for (int[] dir : directions) {
|
||||
int nx = x + dir[0];
|
||||
int ny = y + dir[1];
|
||||
while (nx >= 0 && nx < width && ny >= 0 && ny < height) {
|
||||
if (isEmpty(nx, ny)) {
|
||||
moves.add(new int[]{nx, ny});
|
||||
} else {
|
||||
if (isEnemy(nx, ny, piece.isWhite())) {
|
||||
moves.add(new int[]{nx, ny});
|
||||
}
|
||||
break;
|
||||
}
|
||||
nx += dir[0];
|
||||
ny += dir[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (type == PieceType.Queen) {
|
||||
// Combine Rook + Bishop
|
||||
int[][] directions = {{1,0},{-1,0},{0,1},{0,-1},{1,1},{1,-1},{-1,1},{-1,-1}};
|
||||
for (int[] dir : directions) {
|
||||
int nx = x + dir[0];
|
||||
int ny = y + dir[1];
|
||||
while (nx >= 0 && nx < width && ny >= 0 && ny < height) {
|
||||
if (isEmpty(nx, ny)) {
|
||||
moves.add(new int[]{nx, ny});
|
||||
} else {
|
||||
if (isEnemy(nx, ny, piece.isWhite())) {
|
||||
moves.add(new int[]{nx, ny});
|
||||
}
|
||||
break;
|
||||
}
|
||||
nx += dir[0];
|
||||
ny += dir[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (type == PieceType.Knight) {
|
||||
// 8 mouvements possibles
|
||||
int[][] jumps = {{2,1},{1,2},{-1,2},{-2,1},{-2,-1},{-1,-2},{1,-2},{2,-1}};
|
||||
for (int[] jump : jumps) {
|
||||
int nx = x + jump[0];
|
||||
int ny = y + jump[1];
|
||||
if (nx >= 0 && nx < width && ny >= 0 && ny < height) {
|
||||
if (isEmpty(nx, ny) || isEnemy(nx, ny, piece.isWhite())) {
|
||||
moves.add(new int[]{nx, ny});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (type == PieceType.King) {
|
||||
// 8 directions, une seule case
|
||||
int[][] directions = {{1,0},{-1,0},{0,1},{0,-1},{1,1},{1,-1},{-1,1},{-1,-1}};
|
||||
for (int[] dir : directions) {
|
||||
int nx = x + dir[0];
|
||||
int ny = y + dir[1];
|
||||
if (nx >= 0 && nx < width && ny >= 0 && ny < height) {
|
||||
if (isEmpty(nx, ny) || isEnemy(nx, ny, piece.isWhite())) {
|
||||
moves.add(new int[]{nx, ny});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return moves;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue