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 = [];
int aux1 = 0, aux2 = 0;
aux1 = !reversedBoard ? (super.isWhite ? -1 : 1) : (super.isWhite ? 1 : -1);
if (board[y + aux1][x].isEmpty()) movements.add([y + aux1, x]);
if (x < 7 &&
board[y + aux1][x + 1].color() != isWhite &&
!board[y + aux1][x + 1].isEmpty()) {
movements.add([y + aux1, x + 1]);
}
if (x > 0 &&
board[y + aux1][x - 1].color() != isWhite &&
!board[y + aux1][x - 1].isEmpty()) {
movements.add([y + aux1, x - 1]);
}
aux2 = !reversedBoard ? (super.isWhite ? -2 : 2) : (super.isWhite ? 2 : -2);
if ((!reversedBoard &&
(super.isWhite && y == 6 || !super.isWhite && y == 1)) ||
(reversedBoard &&
(super.isWhite && y == 1 || !super.isWhite && y == 6))) {
if (board[y + aux2][x].isEmpty() && board[y + aux1][x].isEmpty()) {
movements.add([y + aux2, x]);
}
}
//comer al paso
if (lastMovement !=
[
[-1, -1],
[-1, -1]
] &&
(lastMovement[0][0] - lastMovement[1][0]).abs() > 1 &&
((x < 7 &&
lastMovement[0][1] == x + 1 &&
board[y][x + 1] is Pawn &&
board[y][x + 1].color() != isWhite) ||
(x > 0 &&
lastMovement[0][1] == x - 1 &&
board[y][x - 1] is Pawn &&
board[y][x - 1].color() != isWhite))) {
movements.add([y + aux1, lastMovement[0][1]]);
}
return movements;
}