Proper castling notation

This commit is contained in:
Dragon Fire
2021-02-07 15:00:28 -05:00
parent 86bde7c128
commit bc0d470ef0
+21 -2
View File
@@ -7,7 +7,7 @@ const path = require('path');
const { verify, reactIfAble } = require('../../util/Util');
const { centerImagePart } = require('../../util/Canvas');
const { FAILURE_EMOJI_ID } = process.env;
const turnRegex = /^((?:[A-H][1-8])|(?:[PKRQBN]))?([A-H]|X)?(?: |, ?|-?>?)?([A-H][1-8])(?:=([QRNB]))?$/;
const turnRegex = /^(?:((?:[A-H][1-8])|(?:[PKRQBN]))?([A-H]|X)?([A-H][1-8])(?:=([QRNB]))?)|(?:0\-0(?:\-0)?)$/;
const pieces = ['pawn', 'rook', 'knight', 'king', 'queen', 'bishop'];
const cols = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'];
@@ -217,7 +217,26 @@ module.exports = class ChessCommand extends Command {
}
parseSAN(gameState, moves, move) {
if (!move || !move[3]) return null;
if (!move) return null;
if (move[0] === '0-0') {
if (gameState.turn === 'white') {
if (gameState.castling.whiteShort) return ['E1', 'G1'];
return null;
} else if (gameState.turn === 'black') {
if (gameState.castling.blackShort) return ['E8', 'G8'];
return null;
}
}
if (move[0] === '0-0-0') {
if (gameState.turn === 'white') {
if (gameState.castling.whiteLong) return ['E1', 'C1'];
return null;
} else if (gameState.turn === 'black') {
if (gameState.castling.blackLong) return ['E8', 'C8'];
return null;
}
}
if (!move[3]) return null;
const initial = move[1] || 'P';
if (gameState.pieces[initial]) return [initial, move[3], move[4] || 'Q'];
const possiblePieces = Object.keys(gameState.pieces).filter(piece => {