use isDark/isLight more consistently

This commit is contained in:
Jesse D. McDonald 2020-03-14 13:02:52 -05:00
parent 47fc9cba08
commit a77403484c
1 changed files with 9 additions and 9 deletions

View File

@ -70,7 +70,7 @@ function boardGet(board, where, side){
}
function boardPut(board, where, side, piece){
side = isDark(side) ? 'dark' : 'light';
side = normalizeSide(side);
var column = 'abcdefgh'.indexOf(where[0]);
var row = Number(where[1]) - 1;
var data = board[side][row];
@ -368,11 +368,11 @@ function renderHistory(board) {
const took = move.took ? 'x' : '';
result += SHY + '*' + piece + took + move.to;
} else {
if (n > 0 || move.side === 'dark') {
if (n > 0 || isDark(move.side)) {
result += ' ';
}
if (move.side === 'light') {
if (isLight(move.side)) {
++n;
result += String(n) + '.' + NBSP;
}
@ -380,7 +380,7 @@ function renderHistory(board) {
if (move.pass) {
result += '...';
} else if (move.alongside) {
if (move.side === 'light') {
if (isLight(move.side)) {
result += move.type.toUpperCase() + move.alongside.toUpperCase() + move.from + move.to;
} else {
result += move.alongside.toUpperCase() + move.type.toUpperCase() + move.from + move.to;
@ -471,7 +471,7 @@ function renderBoard(board){
}
}
var clss = board.player === 'light' ? '.cb-lt-piece' : '.cb-dk-piece';
var clss = isLight(board.player) ? '.cb-lt-piece' : '.cb-dk-piece';
if (board.phantom) {
var where = board.phantom.from;
@ -497,9 +497,9 @@ function renderBoard(board){
var msg = '';
if (board.move && board.move.took === 'k') {
msg = (board.move.side[0] === 'd' ? 'Dark' : 'Light') + ' player won!';
msg = (isDark(board.move.side) ? 'Dark' : 'Light') + ' player won!';
} else {
msg = (board.player[0] === 'd' ? 'Dark' : 'Light') + " player's move";
msg = (isDark(board.player) ? 'Dark' : 'Light') + " player's move";
}
$('#cb_message').text(msg);
@ -615,9 +615,9 @@ function switchGameId(newId){
/* ignore partial moves and undo/redo */
if (!board.phantom && !board.subsequent) {
if (board.move && board.move.took === 'k') {
notify((board.move.side[0] === 'd' ? 'Dark' : 'Light') + ' player won!');
notify((isDark(board.move.side) ? 'Dark' : 'Light') + ' player won!');
} else {
notify((board.player[0] === 'd' ? 'Dark' : 'Light') + ' player\'s turn');
notify((isDark(board.player) ? 'Dark' : 'Light') + ' player\'s turn');
}
$('#cb_board').data('skip_notify', d.board);
}