aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/render-msg.js18
1 files changed, 15 insertions, 3 deletions
diff --git a/lib/render-msg.js b/lib/render-msg.js
index 7794382..9308495 100644
--- a/lib/render-msg.js
+++ b/lib/render-msg.js
@@ -1315,8 +1315,9 @@ function chessPieceName(c) {
function renderChessSymbol(c, loc) {
var info = chessSymbols[c] || ['?', '', 'unknown']
+ var piece = info && c !== ' ' ? info[1] + ' ' + info[2] : ''
return h('span.symbol', {
- title: info[1] + ' ' + info[2] + (loc ? ' at ' + loc : '')
+ title: piece + (piece && loc ? ' at ' : '') + (loc || '')
}, info[0])
}
@@ -1327,7 +1328,18 @@ function chessLocToIdxs(loc) {
function lookupPiece(board, loc) {
var idxs = chessLocToIdxs(loc)
- return idxs && board[idxs[0]] && board[idxs[0]][idxs[1]]
+ if (!idxs) return
+ var piece = board[idxs[0]] && board[idxs[0]][idxs[1]]
+ if (!piece || piece === ' ') {
+ // detect castling
+ if (idxs[0] === 0 || idxs[0] === 7) {
+ if (idxs[1] === 0) idxs[1]++
+ else if (idxs[1] == 7) idxs[1]--
+ else return piece
+ piece = board[idxs[0]] && board[idxs[0]][idxs[1]]
+ }
+ }
+ return piece
}
function chessIdxsToLoc(i, j) {
@@ -1455,7 +1467,7 @@ RenderMsg.prototype.chessMoveFull = function (cb) {
}),
h('p',
// 'player ', (c.ply || ''), ' ',
- 'moved ', (piece ? [renderChessSymbol(piece), ' '] : ''),
+ piece ? ['moved ', renderChessSymbol(piece), ' '] : '',
'from ' + c.orig, ' ',
'to ' + c.dest
),