let clear_arrows = function() {
for (let i = 0; i < arrows.length; ++i) {
if (arrows[i].svg) {
- if (arrows[i].svg.parentElement) {
- arrows[i].svg.parentElement.removeChild(arrows[i].svg);
- }
+ arrows[i].svg.remove();
delete arrows[i].svg;
}
}
return;
}
- let zoom_factor = document.getElementById("board").getBoundingClientRect().width / 400.0;
+ let board_width = parseInt(document.querySelector(".board-b72b1").style.width, 10);
+ let zoom_factor = board_width / 400.0;
let line_width = arrow.line_width * zoom_factor;
let arrow_size = arrow.arrow_size * zoom_factor;
- let square_width = document.querySelector(".square-a8").getBoundingClientRect().width;
+ let square_width = board_width / 8;
let from_y, to_y, from_x, to_x;
if (board.orientation() === 'black') {
from_y = (arrow.from_row + 0.5)*square_width;
let SVG_NS = "http://www.w3.org/2000/svg";
let XHTML_NS = "http://www.w3.org/1999/xhtml";
let svg = document.createElementNS(SVG_NS, "svg");
- svg.setAttribute("width", /** @type{number} */ (document.getElementById("board").getBoundingClientRect().width));
- svg.setAttribute("height", /** @type{number} */ (document.getElementById("board").getBoundingClientRect().height));
+ svg.setAttribute("width", board_width);
+ svg.setAttribute("height", board_width);
svg.setAttribute("style", "position: absolute");
svg.setAttribute("position", "absolute");
svg.setAttribute("version", "1.1");
let pv_score = undefined;
for (let move in data['refutation_lines']) {
let line = data['refutation_lines'][move];
- let score = compute_score_sort_key(line['score'], line['depth'], invert, false);
+ let score = compute_score_sort_key(line['score'], line['depth'], invert);
if (move == data['pv'][0]) {
pv_score = score;
}
if (score < min_score) min_score = score;
if (score > max_score) max_score = score;
}
+ if (max_score - min_score < 100) {
+ if (Math.abs(max_score) >= Math.abs(min_score)) {
+ max_score = min_score + 100;
+ } else {
+ min_score = max_score - 100;
+ }
+ }
const h = scorespark.getBoundingClientRect().height;
let color;
if (scores[i] === 0) {
color = [0.5, 0.5, 0.5];
- rect.setAttributeNS(null, 'y', base_y - 1);
+ rect.setAttributeNS(null, 'y', base_y);
rect.setAttributeNS(null, 'height', 1);
} else if (scores[i] > 0) {
color = [0.2, 0.4, 0.8];
rect.setAttributeNS(null, 'y', base_y - extent);
- rect.setAttributeNS(null, 'height', extent);
+ rect.setAttributeNS(null, 'height', extent + 1);
} else {
color = [1.0, 0.267, 0.267];
rect.setAttributeNS(null, 'y', base_y);
- rect.setAttributeNS(null, 'height', -extent);
+ rect.setAttributeNS(null, 'height', -extent + 1);
}
let hlcolor = [color[0], color[1], color[2]];
if (scores[i] !== 0) {
* @param {string} fen
*/
let update_imbalance = function(fen) {
- let hiddenboard = new Chess(fen);
let imbalance = {'k': 0, 'q': 0, 'r': 0, 'b': 0, 'n': 0, 'p': 0};
- for (let row = 0; row < 8; ++row) {
- for (let col = 0; col < 8; ++col) {
- let col_text = String.fromCharCode('a1'.charCodeAt(0) + col);
- let row_text = String.fromCharCode('a1'.charCodeAt(1) + row);
- let square = col_text + row_text;
- let contents = hiddenboard.get(square);
- if (contents !== null) {
- if (contents.color === 'w') {
- ++imbalance[contents.type];
- } else {
- --imbalance[contents.type];
- }
- }
+ for (const c of fen) {
+ if (c === ' ') {
+ // End of board
+ break;
+ }
+ if (c != c.toUpperCase()) {
+ --imbalance[c];
+ } else if (c != c.toLowerCase()) {
+ ++imbalance[c.toLowerCase()];
}
}
+
let white_imbalance = document.getElementById('whiteimbalance');
let black_imbalance = document.getElementById('blackimbalance');
white_imbalance.textContent = '';
* @param score The score digest tuple.
* @param {?number} depth Depth the move has been computed to, or null.
* @param {boolean} invert Whether black is to play.
- * @param {boolean=} depth_secondary_key
* @return {number}
*/
-let compute_score_sort_key = function(score, depth, invert, depth_secondary_key) {
+let compute_score_sort_key = function(score, depth, invert) {
let s;
if (!score) {
return -10000000;
}
if (s) {
if (invert) s = -s;
- if (depth_secondary_key) {
- return s * 200 + (depth || 0);
- } else {
- return s;
- }
+ return s;
} else {
return null;
}