var clear_arrows = function() {
for (var i = 0; i < arrows.length; ++i) {
- jsPlumb.detach(arrows[i].connection1);
- jsPlumb.detach(arrows[i].connection2);
+ if (arrows[i].connection1) {
+ jsPlumb.detach(arrows[i].connection1);
+ }
+ if (arrows[i].connection2) {
+ jsPlumb.detach(arrows[i].connection2);
+ }
}
arrows = [];
lineWidth:0,
strokeStyle:arrow.fg_color,
outlineWidth:0,
- outlineColor:"#666",
+ outlineColor:"#666"
},
overlays : [
["Arrow", {
length: arrow_size,
paintStyle: {
lineWidth:line_width,
- strokeStyle:"#000",
- },
+ strokeStyle:"#000"
+ }
}]
]
});
arrows.push(arrow);
}
-var compare_by_sort_key = function(refutation_lines, toplay, a, b) {
+var compare_by_sort_key = function(refutation_lines, a, b) {
var ska = refutation_lines[a].sort_key;
var skb = refutation_lines[b].sort_key;
if (ska < skb) return -1;
return 0;
};
-var compare_by_score = function(refutation_lines, toplay, a, b) {
+var compare_by_score = function(refutation_lines, a, b) {
var sa = parseInt(refutation_lines[b].score_sort_key);
var sb = parseInt(refutation_lines[a].score_sort_key);
- if (toplay == 'B') {
- return sb - sa;
- } else {
- return sa - sb;
- }
+ return sa - sb;
}
// Fake multi-PV using the refutation lines. Find all “relevant” moves,
pv = move_num + '. … ' + move;
toplay = 'W';
++i;
+ ++move_num;
}
- ++move_num;
for ( ; i < pretty_pv.length; ++i) {
var move = "<a class=\"move\" href=\"javascript:show_line(" + (display_lines.length - 1) + ", " + i + ");\">" + pretty_pv[i] + "</a>";
}
var update_refutation_lines = function(board) {
+ if (display_lines.length > 1) {
+ display_lines = [ display_lines[0] ];
+ }
+
var tbl = $("#refutationlines");
tbl.empty();
- moves = [];
+ var moves = [];
for (var move in refutation_lines) {
moves.push(move);
}
var compare = sort_refutation_lines_by_score ? compare_by_score : compare_by_sort_key;
- moves = moves.sort(function(a, b) { return compare(refutation_lines, toplay, a, b) });
+ moves = moves.sort(function(a, b) { return compare(refutation_lines, a, b) });
for (var i = 0; i < moves.length; ++i) {
var line = refutation_lines[moves[i]];
}
var update_board = function(board, data, num_viewers) {
+ display_lines = [];
+
// The headline.
var headline = 'Analysis';
if (data.position.last_move !== 'none') {
- headline += ' after ' + data.position.move_num + '. ';
+ headline += ' after '
if (data.position.toplay == 'W') {
- headline += '… ';
+ headline += (data.position.move_num-1) + '… ';
+ } else {
+ headline += data.position.move_num + '. ';
}
headline += data.position.last_move;
}