- const [initFile, destFile] = (this.subTurn == 1 ? [1, 2] : [7, 6]);
- // Only option is knight / elephant swap:
- if (x == firstRank && y == initFile) {
+ const initDestFile = new Map([[1, 2], [7, 6]]);
+ // Only option is knight --> elephant swap:
+ if (
+ x == firstRank &&
+ !!initDestFile.get(y) &&
+ this.getPiece(x, y) == V.KNIGHT
+ ) {
+ const destFile = initDestFile.get(y);