simulateMovement function
Function that given a movement coords simulates it, is used to simulate opponents moves.
Implementation
void simulateMovement(List<List<int>> movements) {
BoardData b = BoardData();
int auxY = movements[0][0];
int auxX = movements[0][1];
int y = movements[1][0];
int x = movements[1][1];
processCastling(auxY, auxX, y, x);
procesarComerAlPaso(auxY, auxX, y, x);
b.lastMovement = movements;
final musicPlayer = AudioPlayer();
if (b.currentBoard[y][x].isEmpty()) {
musicPlayer.play(AssetSource("sounds/movePiece.mp3"));
} else {
musicPlayer.play(AssetSource("sounds/capturePiece.mp3"));
}
b.currentBoard[y][x] = b.currentBoard[auxY][auxX];
if (b.prom != "") {
switch (b.prom) {
case "q":
b.currentBoard[y][x] = Queen(isWhite: b.whiteTurn);
break;
case "r":
b.currentBoard[y][x] = Rook(isWhite: b.whiteTurn);
break;
case "b":
b.currentBoard[y][x] = Bishop(isWhite: b.whiteTurn);
break;
case "n":
b.currentBoard[y][x] = Knight(isWhite: b.whiteTurn);
break;
}
}
b.prom = "";
b.currentBoard[auxY][auxX] = Empty(isWhite: false);
b.selectedSquare = [-1, -1];
(b.squares[auxY * 8 + auxX] as SquareState).actualizarEstado();
(b.squares[y * 8 + x] as SquareState).actualizarEstado();
// updateSquares();
for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
if (b.boardMovements[i][j]) {
b.boardMovements[i][j] = false;
(b.squares[i * 8 + j] as SquareState).actualizarEstado();
}
}
}
b.whiteTurn = !b.whiteTurn;
}