Skip to content

Commit

Permalink
improve support for games where black starts, in round replay
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Jun 9, 2015
1 parent 8efb198 commit 8695073
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
4 changes: 2 additions & 2 deletions ui/analyse/src/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ function renderTree(ctrl, tree) {
var turns = [];
var initPly = ctrl.analyse.firstPly();
if (initPly % 2 === 0)
for (i = 1, nb = tree.length; i < nb; i += 2) turns.push({
for (var i = 1, nb = tree.length; i < nb; i += 2) turns.push({
turn: Math.floor((initPly + i) / 2) + 1,
white: tree[i],
black: tree[i + 1]
Expand All @@ -218,7 +218,7 @@ function renderTree(ctrl, tree) {
white: null,
black: tree[1]
});
for (i = 2, nb = tree.length; i < nb; i += 2) turns.push({
for (var i = 2, nb = tree.length; i < nb; i += 2) turns.push({
turn: Math.floor((initPly + i) / 2) + 1,
white: tree[i],
black: tree[i + 1]
Expand Down
1 change: 1 addition & 0 deletions ui/round/src/ctrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ module.exports = function(opts) {
}
if (this.data.game.threefold) this.data.game.threefold = false;
this.data.steps.push({
ply: this.lastPly() + 1,
fen: o.fen,
san: o.san,
uci: o.uci,
Expand Down
29 changes: 17 additions & 12 deletions ui/round/src/view/replay.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@ var status = require('game').status;
var renderStatus = require('./status');
var m = require('mithril');

function renderTd(move, ply, curPly) {
return move ? {
var emptyTd = m('td', '...');

function renderTd(step, curPly) {
return step ? {
tag: 'td',
attrs: {
class: 'move' + (ply === curPly ? ' active' : ''),
'data-ply': ply
class: 'move' + (step.ply === curPly ? ' active' : ''),
'data-ply': step.ply
},
children: [move]
} : null;
children: [step.san]
} : emptyTd
}

function renderResult(ctrl, asTable) {
Expand Down Expand Up @@ -51,17 +53,20 @@ function renderTable(ctrl) {
var firstPly = ctrl.firstPly();
var lastPly = ctrl.lastPly();
if (typeof lastPly === 'undefined') return;

var pairs = [];
for (var i = 1, len = steps.length; i < len; i += 2) pairs.push([
steps[i].san,
steps[i + 1] ? steps[i + 1].san : null
]);
if (firstPly % 2 === 0)
for (var i = 1, len = steps.length; i < len; i += 2) pairs.push([steps[i], steps[i + 1]]);
else {
pairs.push([null, steps[1]]);
for (var i = 2, len = steps.length; i < len; i += 2) pairs.push([steps[i], steps[i + 1]]);
}

var trs = pairs.map(function(pair, i) {
return m('tr', [
m('td.index', i + 1),
renderTd(pair[0], 2 * i + 1 + firstPly, ctrl.vm.ply),
renderTd(pair[1], 2 * i + 2 + firstPly, ctrl.vm.ply)
renderTd(pair[0], ctrl.vm.ply),
renderTd(pair[1], ctrl.vm.ply)
]);
}).concat(renderResult(ctrl, true));
return m('table',
Expand Down

0 comments on commit 8695073

Please sign in to comment.