From bc0d470ef042d8d7818c345649e20b7e0fb48c8d Mon Sep 17 00:00:00 2001 From: Dragon Fire Date: Sun, 7 Feb 2021 15:00:28 -0500 Subject: [PATCH] Proper castling notation --- commands/games-mp/chess.js | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/commands/games-mp/chess.js b/commands/games-mp/chess.js index 8975286a..a0d8576a 100644 --- a/commands/games-mp/chess.js +++ b/commands/games-mp/chess.js @@ -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 => {