allow short promotion style (a8q) in keyboard moves

This commit is contained in:
Thibault Duplessis 2019-05-01 14:37:31 +07:00
parent a3d25550ba
commit b4f35a84e4

View file

@ -4,8 +4,8 @@ import { DecodedDests } from '../interfaces';
const keyRegex = /^[a-h][1-8]$/;
const fileRegex = /^[a-h]$/;
const crazyhouseRegex = /^\w?@[a-h][1-8]$/;
const ambiguousPromotionRegex = /^([a-h]x?)?[a-h](1|8)$/;
const promotionRegex = /^([a-h]x?)?[a-h](1|8)=\w$/;
const ambiguousPromotionCaptureRegex = /^([a-h]x?)?[a-h](1|8)$/;
const promotionRegex = /^([a-h]x?)?[a-h](1|8)=?[nbrq]$/;
window.lichess.keyboardMove = function(opts: any) {
if (opts.input.classList.contains('ready')) return;
@ -21,7 +21,7 @@ window.lichess.keyboardMove = function(opts: any) {
// ambiguous UCI
if (v.match(keyRegex) && opts.hasSelected()) opts.select(v);
// ambiguous promotion (also check sans[v] here because bc8 could mean Bc8)
if (v.match(ambiguousPromotionRegex) && sans[v] && !force) return;
if (v.match(ambiguousPromotionCaptureRegex) && sans[v] && !force) return;
else opts.san(foundUci.slice(0, 2), foundUci.slice(2));
clear();
} else if (sans && v.match(keyRegex)) {
@ -30,7 +30,7 @@ window.lichess.keyboardMove = function(opts: any) {
} else if (sans && v.match(fileRegex)) {
// do nothing
} else if (sans && v.match(promotionRegex)) {
const foundUci = sanToUci(v.slice(0, -2), sans);
const foundUci = sanToUci(v.replace('=', '').slice(0, -1), sans);
if (!foundUci) return;
opts.promote(foundUci.slice(0, 2), foundUci.slice(2), v.slice(-1).toUpperCase());
clear();