mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
Proper castling notation
This commit is contained in:
@@ -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 => {
|
||||
|
||||
Reference in New Issue
Block a user