Updated renderSan()

If the replace function is removed, the if statements for adding "check" and "checkmate" to the string are no longer required.  Also, changed "promotion" to "promotes to".  I thought "f8 promotes to queen" sounded better than "f8 promotion queen".

Sorry for so many edits to this file!  I hope this will be the last one it needs for a long time.
pull/5392/head
mblemberg 2019-08-04 13:41:54 -05:00 committed by GitHub
parent 4efac1faed
commit db0d3caabf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 4 deletions

View File

@ -4,19 +4,17 @@ function renderSan(san: San) {
let move: string;
if (san.includes('O-O-O')) move = 'long castle';
else if (san.includes('O-O')) move = 'short castle';
else move = san.replace(/[\+#]/, '').split('').map(c => {
else move = san.split('').map(c => {
if (c == 'x') return 'takes';
if (c == '+') return 'check';
if (c == '#') return 'checkmate';
if (c == '=') return 'promotion';
if (c == '=') return 'promotes to';
if (c == '@') return 'at';
const code = c.charCodeAt(0);
if (code > 48 && code < 58) return c; // 1-8
if (code > 96 && code < 105) return c.toUpperCase();
return roles[c] || c;
}).join(' ');
if (san.includes('+')) move += ' check';
if (san.includes('#')) move += ' checkmate';
return move;
}