decodeMovement function
- String jugada
Function that given a string movement decodes it in movement coords.
Implementation
List<List<int>> decodeMovement(String jugada) {
var jugadas = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'];
int prevx = jugadas.indexOf(jugada[0]);
int x = jugadas.indexOf(jugada[2]);
int prevy = jugada[1].codeUnitAt(0) - '0'.codeUnitAt(0);
int y = jugada[3].codeUnitAt(0) - '0'.codeUnitAt(0);
BoardData board = BoardData();
if (jugada.length == 5) {
board.prom = jugada[4];
} else {
board.prom = "";
}
prevy = board.reversedBoard ? prevy - 1 : 8 - prevy;
y = board.reversedBoard ? y - 1 : 8 - y;
prevx = !board.reversedBoard ? prevx : 7 - prevx;
x = !board.reversedBoard ? x : 7 - x;
return [
[prevy, prevx],
[y, x]
];
}