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 = [];
movements.add([y - 1, x - 1]);
movements.add([y, x - 1]);
movements.add([y + 1, x - 1]);
movements.add([y - 1, x]);
movements.add([y + 1, x]);
movements.add([y - 1, x + 1]);
movements.add([y, x + 1]);
movements.add([y + 1, x + 1]);
if ((x + 3) < 8 &&
isWhite &&
board[y][x + 3] is Rook &&
board[y][x + 2] is Empty &&
board[y][x + 1] is Empty &&
board[y][x] is King &&
!(board[y][x + 3] as Rook).alreadyMoved &&
!(board[y][x] as King).alreadyMoved) {
movements.add([y, x + 2]);
}
if ((x - 4) >= 0 &&
isWhite &&
board[y][x - 4] is Rook &&
board[y][x - 3] is Empty &&
board[y][x - 2] is Empty &&
board[y][x - 1] is Empty &&
board[y][x] is King &&
!(board[y][x - 4] as Rook).alreadyMoved &&
!(board[y][x] as King).alreadyMoved) {
movements.add([y, x - 2]);
}
if ((x - 3) >= 0 &&
!isWhite &&
board[y][x - 3] is Rook &&
board[y][x - 2] is Empty &&
board[y][x - 1] is Empty &&
board[y][x] is King &&
!(board[y][x - 3] as Rook).alreadyMoved &&
!(board[y][x] as King).alreadyMoved) {
movements.add([y, x - 2]);
}
if ((x + 4) < 8 &&
!isWhite &&
board[y][x + 4] is Rook &&
board[y][x + 3] is Empty &&
board[y][x + 2] is Empty &&
board[y][x + 1] is Empty &&
board[y][x] is King &&
!(board[y][x + 4] as Rook).alreadyMoved &&
!(board[y][x] as King).alreadyMoved) {
movements.add([y, x + 2]);
}
return movements;
}