possibleMovements method
override
Implementation
@override
List<List<int>> possibleMovements(int x, int y, List<List<Piece>> board,
bool reversedBoard, List<List<int>> lastMovement) {
List<List<int>> movements = [];
for (int i = y + 1; i < 8; i++) {
if (board[i][x].isEmpty()) {
movements.add([i, x]);
} else {
if (board[i][x].isWhite != isWhite) {
movements.add([i, x]);
}
break;
}
}
for (int i = y - 1; i >= 0; i--) {
if (board[i][x].isEmpty()) {
movements.add([i, x]);
} else {
if (board[i][x].isWhite != isWhite) {
movements.add([i, x]);
}
break;
}
}
for (int i = x + 1; i < 8; i++) {
if (board[y][i].isEmpty()) {
movements.add([y, i]);
} else {
if (board[y][i].isWhite != isWhite) {
movements.add([y, i]);
}
break;
}
}
for (int i = x - 1; i >= 0; i--) {
if (board[y][i].isEmpty()) {
movements.add([y, i]);
} else {
if (board[y][i].isWhite != isWhite) {
movements.add([y, i]);
}
break;
}
}
for (int i = 1; i < 8; i++) {
if ((x + i < 8 && y + i < 8) && board[y + i][x + i].isEmpty()) {
movements.add([y + i, x + i]);
} else {
if ((x + i < 8 && y + i < 8) &&
board[y + i][x + i].isWhite != isWhite) {
movements.add([y + i, x + i]);
}
break;
}
}
for (int i = 1; i < 8; i++) {
if ((x - i >= 0 && y - i >= 0) && board[y - i][x - i].isEmpty()) {
movements.add([y - i, x - i]);
} else {
if ((x - i >= 0 && y - i >= 0) &&
board[y - i][x - i].isWhite != isWhite) {
movements.add([y - i, x - i]);
}
break;
}
}
for (int i = 1; i < 8; i++) {
if ((x + i < 8 && y - i >= 0) && board[y - i][x + i].isEmpty()) {
movements.add([y - i, x + i]);
} else {
if ((x + i < 8 && y - i >= 0) &&
board[y - i][x + i].isWhite != isWhite) {
movements.add([y - i, x + i]);
}
break;
}
}
for (int i = 1; i < 8; i++) {
if ((x - i >= 0 && y + i < 8) && board[y + i][x - i].isEmpty()) {
movements.add([y + i, x - i]);
} else {
if ((x - i >= 0 && y + i < 8) &&
board[y + i][x - i].isWhite != isWhite) {
movements.add([y + i, x - i]);
}
break;
}
}
return movements;
}