UI refresh: UX layer, Users/Errors/Event redesign, board analyser #10
No files matched your search
@@ -0,0 +1,500 @@
|
||||
/* ===========================================================================
|
||||
OpenBench - board analyser ( event page )
|
||||
Loaded after ux.css. Layout: the board on the left, the moves and the
|
||||
evaluation graph on the right, with both columns the same height.
|
||||
=========================================================================== */
|
||||
|
||||
:root {
|
||||
--bd-light: #E3E8F1;
|
||||
--bd-dark: #7A8FB3;
|
||||
}
|
||||
|
||||
/* ---------- Layout ---------- */
|
||||
|
||||
.bd-layout {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 640px) minmax(0, 1fr);
|
||||
gap: 20px;
|
||||
align-items: stretch;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.bd-layout .card {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.bd-card {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.bd-body {
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
/* The right column does not add to the row height, so it always matches the board */
|
||||
.ev-right {
|
||||
position: relative;
|
||||
min-width: 0;
|
||||
min-height: 560px;
|
||||
}
|
||||
|
||||
.ev-right-inner {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.ev-moves-card {
|
||||
display: flex;
|
||||
flex: 1 1 0;
|
||||
flex-direction: column;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.ev-moves-card .ev-movelist {
|
||||
flex: 1 1 0;
|
||||
min-height: 0;
|
||||
max-height: none;
|
||||
}
|
||||
|
||||
.bd-graph-card {
|
||||
flex: none;
|
||||
}
|
||||
|
||||
/* ---------- Board ---------- */
|
||||
|
||||
.bd-grid {
|
||||
display: grid;
|
||||
grid-template-columns: 28px minmax(0, 1fr);
|
||||
column-gap: 12px;
|
||||
row-gap: 10px;
|
||||
}
|
||||
|
||||
#bd-top { grid-column: 2; grid-row: 1; }
|
||||
.bd-eval { grid-column: 1; grid-row: 2; }
|
||||
.bd-board { grid-column: 2; grid-row: 2; }
|
||||
#bd-bottom { grid-column: 2; grid-row: 3; }
|
||||
|
||||
.bd-board {
|
||||
aspect-ratio: 1;
|
||||
border-radius: var(--radius);
|
||||
box-shadow: 0 0 0 1px var(--line-strong), 0 8px 22px rgba(0, 0, 0, 0.35);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.bd-board svg {
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.bd-nojs {
|
||||
margin: 0;
|
||||
padding: 24px;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.bd-light { fill: var(--bd-light); }
|
||||
.bd-dark { fill: var(--bd-dark); }
|
||||
|
||||
.bd-hl-from { fill: rgba(250, 204, 21, 0.38); }
|
||||
.bd-hl-to { fill: rgba(250, 204, 21, 0.55); }
|
||||
.bd-hl-bad { fill: rgba(248, 113, 113, 0.5); }
|
||||
|
||||
.bd-check-in { stop-color: #F87171; stop-opacity: 0.95; }
|
||||
.bd-check-out { stop-color: #F87171; stop-opacity: 0; }
|
||||
|
||||
.bd-coord {
|
||||
font: 600 17px var(--font-sans);
|
||||
pointer-events: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.bd-coord.on-dark { fill: var(--bd-light); }
|
||||
.bd-coord.on-light { fill: var(--bd-dark); }
|
||||
|
||||
.bd-arrow { opacity: 0.92; }
|
||||
.bd-arrow line { stroke: #F87171; }
|
||||
.bd-arrow polygon { fill: #F87171; }
|
||||
|
||||
/* ---------- Evaluation bar ---------- */
|
||||
|
||||
.bd-eval {
|
||||
position: relative;
|
||||
align-self: stretch;
|
||||
background-color: #161B26;
|
||||
border-radius: var(--radius);
|
||||
box-shadow: 0 0 0 1px var(--line-strong);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.bd-eval::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
left: 0;
|
||||
right: 0;
|
||||
height: 1px;
|
||||
background-color: rgba(120, 130, 150, 0.55);
|
||||
}
|
||||
|
||||
.bd-eval-fill {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
height: 50%;
|
||||
background-color: #EDF0F6;
|
||||
transition: height 0.25s ease;
|
||||
}
|
||||
|
||||
.bd-eval.is-flipped .bd-eval-fill {
|
||||
top: 0;
|
||||
bottom: auto;
|
||||
}
|
||||
|
||||
.bd-eval-label {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
right: 0;
|
||||
z-index: 1;
|
||||
font: 600 10.5px var(--font-mono);
|
||||
letter-spacing: -0.03em;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.bd-eval-label.on-white { bottom: 6px; color: #161B26; }
|
||||
.bd-eval-label.on-black { top: 6px; color: #E6EAF2; }
|
||||
|
||||
.bd-eval.is-flipped .bd-eval-label.on-white { top: 6px; bottom: auto; }
|
||||
.bd-eval.is-flipped .bd-eval-label.on-black { bottom: 6px; top: auto; }
|
||||
|
||||
/* ---------- Players, captured pieces ---------- */
|
||||
|
||||
.bd-player {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
min-width: 0;
|
||||
min-height: 34px;
|
||||
}
|
||||
|
||||
.bd-player .ev-piece {
|
||||
flex: none;
|
||||
width: 12px;
|
||||
height: 12px;
|
||||
}
|
||||
|
||||
.bd-player.is-white .ev-piece { background-color: #F1F4FA; }
|
||||
.bd-player.is-black .ev-piece { background-color: #0B0E14; }
|
||||
|
||||
.bd-player.is-turn .ev-piece {
|
||||
box-shadow: 0 0 0 2px var(--color2), 0 0 0 4px var(--accent);
|
||||
}
|
||||
|
||||
.bd-name {
|
||||
flex: 0 1 auto;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
color: var(--color-font1);
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.bd-caps {
|
||||
display: flex;
|
||||
flex: 1 1 auto;
|
||||
align-items: center;
|
||||
min-width: 0;
|
||||
padding-left: 6px;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.bd-cap {
|
||||
flex: none;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
}
|
||||
|
||||
.bd-cap + .bd-cap {
|
||||
margin-left: -9px;
|
||||
}
|
||||
|
||||
.bd-mat {
|
||||
flex: none;
|
||||
color: var(--muted);
|
||||
font: 600 12px var(--font-mono);
|
||||
}
|
||||
|
||||
/* ---------- Status, controls, FEN ---------- */
|
||||
|
||||
.bd-status {
|
||||
min-height: 20px;
|
||||
margin: 14px 0 0;
|
||||
color: var(--color-font2);
|
||||
font-size: 13px;
|
||||
font-weight: 500;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.bd-status.is-bad { color: var(--bad); }
|
||||
.bd-status.is-warn { color: var(--warn); }
|
||||
|
||||
.bd-controls {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(5, minmax(0, 1fr)) 52px;
|
||||
gap: 8px;
|
||||
margin-top: 12px;
|
||||
}
|
||||
|
||||
.bd-card .bd-btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 40px;
|
||||
padding: 0;
|
||||
background-color: var(--color3);
|
||||
border: 1px solid var(--line-strong);
|
||||
border-radius: var(--radius);
|
||||
color: var(--color-font1);
|
||||
font-size: 14px;
|
||||
cursor: pointer;
|
||||
transition: background-color 0.12s ease, border-color 0.12s ease;
|
||||
}
|
||||
|
||||
.bd-card .bd-btn:hover:not(:disabled) {
|
||||
background-color: var(--surface-hover);
|
||||
border-color: var(--accent);
|
||||
}
|
||||
|
||||
.bd-card .bd-btn:focus-visible {
|
||||
outline: 2px solid var(--accent);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
|
||||
.bd-card .bd-btn:disabled {
|
||||
opacity: 0.4;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.bd-card .bd-btn-main {
|
||||
background-color: var(--accent);
|
||||
border-color: var(--accent);
|
||||
color: #FFFFFF;
|
||||
}
|
||||
|
||||
.bd-card .bd-btn-main:hover:not(:disabled) {
|
||||
background-color: var(--accent-hover);
|
||||
border-color: var(--accent-hover);
|
||||
}
|
||||
|
||||
.bd-card .bd-btn-main.is-playing {
|
||||
background-color: var(--accent-soft);
|
||||
border-color: var(--accent);
|
||||
color: var(--color-font1);
|
||||
}
|
||||
|
||||
.bd-card .bd-btn-flip {
|
||||
margin-left: 4px;
|
||||
}
|
||||
|
||||
.bd-fen {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
margin-top: 12px;
|
||||
padding: 5px 5px 5px 12px;
|
||||
background-color: var(--color1);
|
||||
border: 1px solid var(--line);
|
||||
border-radius: var(--radius);
|
||||
}
|
||||
|
||||
.bd-fen-label {
|
||||
flex: none;
|
||||
color: var(--muted);
|
||||
font-size: 11px;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.1em;
|
||||
}
|
||||
|
||||
.bd-fen code {
|
||||
flex: 1 1 auto;
|
||||
min-width: 0;
|
||||
padding: 0;
|
||||
overflow: hidden;
|
||||
background: none;
|
||||
color: var(--color-font2);
|
||||
font-family: var(--font-mono);
|
||||
font-size: 12px;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.bd-card .bd-btn-icon {
|
||||
flex: none;
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
}
|
||||
|
||||
/* ---------- Moves card ---------- */
|
||||
|
||||
.ev-moves-card .ev-sel {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 10px 16px;
|
||||
padding: 14px 16px;
|
||||
border-bottom: 1px solid var(--line);
|
||||
}
|
||||
|
||||
.ev-moves-card .ev-sel-main {
|
||||
flex: 1 1 auto;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.ev-moves-card .ev-sel-san {
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
.ev-sel-counter {
|
||||
margin-left: auto;
|
||||
color: var(--muted);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.ev-moves-card .ev-sel-stats {
|
||||
grid-template-columns: repeat(3, minmax(64px, auto));
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.ev-moves-card .ev-sel-note {
|
||||
flex-basis: 100%;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.ev-moves-foot {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px 18px;
|
||||
padding: 10px 16px;
|
||||
border-top: 1px solid var(--line);
|
||||
color: var(--muted);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.ev-moves-foot kbd {
|
||||
display: inline-block;
|
||||
min-width: 20px;
|
||||
padding: 1px 6px;
|
||||
background-color: var(--color3);
|
||||
border: 1px solid var(--line-strong);
|
||||
border-bottom-width: 2px;
|
||||
border-radius: var(--radius);
|
||||
color: var(--color-font2);
|
||||
font: 11px var(--font-mono);
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
/* ---------- Evaluation graph ---------- */
|
||||
|
||||
.bd-graph-wrap {
|
||||
padding: 14px 16px 16px;
|
||||
}
|
||||
|
||||
.bd-graph {
|
||||
height: 132px;
|
||||
background-color: #363F54;
|
||||
border: 1px solid var(--line-strong);
|
||||
border-radius: var(--radius);
|
||||
cursor: crosshair;
|
||||
overflow: hidden;
|
||||
touch-action: none;
|
||||
}
|
||||
|
||||
.bd-graph svg {
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
.bd-area-white { fill: rgba(237, 240, 246, 0.88); }
|
||||
.bd-area-black { fill: rgba(11, 14, 20, 0.92); }
|
||||
|
||||
.bd-mid {
|
||||
stroke: rgba(255, 255, 255, 0.28);
|
||||
stroke-width: 1;
|
||||
vector-effect: non-scaling-stroke;
|
||||
}
|
||||
|
||||
.bd-curve {
|
||||
fill: none;
|
||||
stroke: var(--accent-hover);
|
||||
stroke-width: 2;
|
||||
stroke-linejoin: round;
|
||||
vector-effect: non-scaling-stroke;
|
||||
}
|
||||
|
||||
.bd-cursor {
|
||||
stroke: var(--accent);
|
||||
stroke-width: 2;
|
||||
vector-effect: non-scaling-stroke;
|
||||
}
|
||||
|
||||
/* ---------- Responsive ---------- */
|
||||
|
||||
@media (max-width: 1180px) {
|
||||
|
||||
.bd-layout {
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
}
|
||||
|
||||
.bd-card {
|
||||
width: 100%;
|
||||
max-width: 640px;
|
||||
justify-self: center;
|
||||
}
|
||||
|
||||
.ev-right {
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.ev-right-inner {
|
||||
position: static;
|
||||
}
|
||||
|
||||
.ev-moves-card {
|
||||
flex: none;
|
||||
}
|
||||
|
||||
.ev-moves-card .ev-movelist {
|
||||
flex: none;
|
||||
max-height: 420px;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 767px) {
|
||||
|
||||
.bd-body {
|
||||
padding: 12px;
|
||||
}
|
||||
|
||||
.bd-grid {
|
||||
grid-template-columns: 22px minmax(0, 1fr);
|
||||
column-gap: 8px;
|
||||
}
|
||||
|
||||
.bd-eval-label {
|
||||
font-size: 9px;
|
||||
}
|
||||
|
||||
.bd-controls {
|
||||
grid-template-columns: repeat(5, minmax(0, 1fr)) 44px;
|
||||
gap: 6px;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,502 @@
|
||||
/* OpenBench board analyser.
|
||||
|
||||
Replays the PGN of an event position by position ( see chess.js ), and draws
|
||||
- the board, with the last move, checks, and any illegal move that was tried
|
||||
- an evaluation bar and an evaluation graph, from the engine comments
|
||||
- captured pieces and material for both sides
|
||||
|
||||
event_viewer.js owns the selected move and tells us about it with the
|
||||
"ob:ply" event. We only draw, and ask window.OpenBenchViewer to move.
|
||||
|
||||
Piece artwork: "Cburnett" set by Colin M.L. Burnett, GPL-2.0-or-later.
|
||||
https://en.wikipedia.org/wiki/User:Cburnett/GFDL_images/Chess */
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var Chess = window.OBChess;
|
||||
var host = document.getElementById('bd-board');
|
||||
|
||||
if (!Chess || !host) return;
|
||||
|
||||
|
||||
var NS = 'http://www.w3.org/2000/svg';
|
||||
|
||||
function $(id) { return document.getElementById(id); }
|
||||
|
||||
function readJSON(id, fallback) {
|
||||
var element = $(id);
|
||||
if (!element) return fallback;
|
||||
try { return JSON.parse(element.textContent); } catch (error) { return fallback; }
|
||||
}
|
||||
|
||||
var game = readJSON('ev-game', null);
|
||||
var moves = readJSON('ev-moves', []);
|
||||
|
||||
if (!game || !moves.length) return;
|
||||
|
||||
var total = moves.length;
|
||||
var replayed = Chess.replay(game.startFen, moves.map(function (move) { return move.san; }));
|
||||
var positions = replayed.positions; // positions[i] is the board after i moves
|
||||
var problem = replayed.error;
|
||||
var attempt = Chess.findUciMove(game.note);
|
||||
|
||||
var current = total;
|
||||
var flipped = false;
|
||||
var timer = null;
|
||||
|
||||
try { flipped = window.localStorage.getItem('ob:board:flipped') === '1'; } catch (error) { /* ignore */ }
|
||||
|
||||
/* ---------- Evaluations, from the White point of view ---------- */
|
||||
|
||||
var evals = [{ value: null, label: '\u2013' }];
|
||||
|
||||
moves.forEach(function (move) {
|
||||
|
||||
var raw = move.eval;
|
||||
|
||||
if (!raw) return evals.push({ value: null, label: '\u2013' });
|
||||
if (raw === 'book') return evals.push({ value: null, label: 'book' });
|
||||
|
||||
var body = raw.replace(/^[+-]/, '');
|
||||
var mate = body.charAt(0) === 'M';
|
||||
var magnitude = mate ? 100 : parseFloat(body);
|
||||
|
||||
if (isNaN(magnitude)) return evals.push({ value: null, label: '\u2013' });
|
||||
|
||||
// The comment is from the point of view of the side that moved
|
||||
var value = (raw.charAt(0) === '-' ? -magnitude : magnitude) * (move.color === 'b' ? -1 : 1);
|
||||
|
||||
var label = mate ? (value < 0 ? '-' : '') + body : (value > 0 ? '+' : '') + value.toFixed(1);
|
||||
|
||||
evals.push({ value: value, label: label });
|
||||
});
|
||||
|
||||
var hasEvals = evals.some(function (entry) { return entry.value !== null; });
|
||||
|
||||
// Squashes pawns into -1 .. +1, so that a mate does not flatten everything else
|
||||
function squash(pawns) {
|
||||
return 2 / (1 + Math.exp(-pawns / 2.2)) - 1;
|
||||
}
|
||||
|
||||
/* ---------- Piece artwork, shared by every board and tray ---------- */
|
||||
|
||||
var PIECES = {
|
||||
wK: '<g fill="none" fill-rule="evenodd" stroke="#000" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M22.5 11.63V6M20 8h5" stroke-linejoin="miter"/><path d="M22.5 25s4.5-7.5 3-10.5c0 0-1-2.5-3-2.5s-3 2.5-3 2.5c-1.5 3 3 10.5 3 10.5" fill="#fff" stroke-linecap="butt" stroke-linejoin="miter"/><path d="M11.5 37c5.5 3.5 15.5 3.5 21 0v-7s9-4.5 6-10.5c-4-6.5-13.5-3.5-16 4V27v-3.5c-3.5-7.5-13-10.5-16-4-3 6 5 10 5 10V37z" fill="#fff"/><path d="M11.5 30c5.5-3 15.5-3 21 0m-21 3.5c5.5-3 15.5-3 21 0m-21 3.5c5.5-3 15.5-3 21 0"/></g>',
|
||||
wQ: '<g fill="#fff" fill-rule="evenodd" stroke="#000" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M8 12a2 2 0 1 1-4 0 2 2 0 1 1 4 0zm16.5-4.5a2 2 0 1 1-4 0 2 2 0 1 1 4 0zM41 12a2 2 0 1 1-4 0 2 2 0 1 1 4 0zM16 8.5a2 2 0 1 1-4 0 2 2 0 1 1 4 0zM33 9a2 2 0 1 1-4 0 2 2 0 1 1 4 0z"/><path d="M9 26c8.5-1.5 21-1.5 27 0l2-12-7 11V11l-5.5 13.5-3-15-3 15-5.5-14V25L7 14l2 12z" stroke-linecap="butt"/><path d="M9 26c0 2 1.5 2 2.5 4 1 1.5 1 1 .5 3.5-1.5 1-1.5 2.5-1.5 2.5-1.5 1.5.5 2.5.5 2.5 6.5 1 16.5 1 23 0 0 0 1.5-1 0-2.5 0 0 .5-1.5-1-2.5-.5-2.5-.5-2 .5-3.5 1-2 2.5-2 2.5-4-8.5-1.5-18.5-1.5-27 0z" stroke-linecap="butt"/><path d="M11.5 30c3.5-1 18.5-1 22 0M12 33.5c6-1 15-1 21 0" fill="none"/></g>',
|
||||
wR: '<g fill="#fff" fill-rule="evenodd" stroke="#000" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M9 39h27v-3H9v3zm3-3v-4h21v4H12zm-1-22V9h4v2h5V9h5v2h5V9h4v5" stroke-linecap="butt"/><path d="M34 14l-3 3H14l-3-3"/><path d="M31 17v12.5H14V17" stroke-linecap="butt" stroke-linejoin="miter"/><path d="M31 29.5l1.5 2.5h-20l1.5-2.5"/><path d="M11 14h23" fill="none" stroke-linejoin="miter"/></g>',
|
||||
wB: '<g fill="none" fill-rule="evenodd" stroke="#000" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><g fill="#fff" stroke-linecap="butt"><path d="M9 36c3.39-.97 10.11.43 13.5-2 3.39 2.43 10.11 1.03 13.5 2 0 0 1.65.54 3 2-.68.97-1.65.99-3 .5-3.39-.97-10.11.46-13.5-1-3.39 1.46-10.11.03-13.5 1-1.354.49-2.323.47-3-.5 1.354-1.94 3-2 3-2z"/><path d="M15 32c2.5 2.5 12.5 2.5 15 0 .5-1.5 0-2 0-2 0-2.5-2.5-4-2.5-4 5.5-1.5 6-11.5-5-15.5-11 4-10.5 14-5 15.5 0 0-2.5 1.5-2.5 4 0 0-.5.5 0 2z"/><path d="M25 8a2.5 2.5 0 1 1-5 0 2.5 2.5 0 1 1 5 0z"/></g><path d="M17.5 26h10M15 30h15m-7.5-14.5v5M20 18h5" stroke-linejoin="miter"/></g>',
|
||||
wN: '<g fill="none" fill-rule="evenodd" stroke="#000" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M22 10c10.5 1 16.5 8 16 29H15c0-9 10-6.5 8-21" fill="#fff"/><path d="M24 18c.38 2.91-5.55 7.37-8 9-3 2-2.82 4.34-5 4-1.042-.94 1.41-3.04 0-3-1 0 .19 1.23-1 2-1 0-4.003 1-4-4 0-2 6-12 6-12s1.89-1.9 2-3.5c-.73-.994-.5-2-.5-3 1-1 3 2.5 3 2.5h2s.78-1.992 2.5-3c1 0 1 3 1 3" fill="#fff"/><path d="M9.5 25.5a.5.5 0 1 1-1 0 .5.5 0 1 1 1 0zm5.433-9.75a.5 1.5 30 1 1-.866-.5.5 1.5 30 1 1 .866.5z" fill="#000"/></g>',
|
||||
wP: '<path d="M22.5 9c-2.21 0-4 1.79-4 4 0 .89.29 1.71.78 2.38C17.33 16.5 16 18.59 16 21c0 2.03.94 3.84 2.41 5.03-3 1.06-7.41 5.55-7.41 13.47h23c0-7.92-4.41-12.41-7.41-13.47 1.47-1.19 2.41-3 2.41-5.03 0-2.41-1.33-4.5-3.28-5.62.49-.67.78-1.49.78-2.38 0-2.21-1.79-4-4-4z" fill="#fff" stroke="#000" stroke-width="1.5" stroke-linecap="round"/>',
|
||||
bK: '<g fill="none" fill-rule="evenodd" stroke="#000" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M22.5 11.63V6" stroke-linejoin="miter"/><path d="M22.5 25s4.5-7.5 3-10.5c0 0-1-2.5-3-2.5s-3 2.5-3 2.5c-1.5 3 3 10.5 3 10.5" fill="#000" stroke-linecap="butt" stroke-linejoin="miter"/><path d="M11.5 37c5.5 3.5 15.5 3.5 21 0v-7s9-4.5 6-10.5c-4-6.5-13.5-3.5-16 4V27v-3.5c-3.5-7.5-13-10.5-16-4-3 6 5 10 5 10V37z" fill="#000"/><path d="M20 8h5" stroke-linejoin="miter"/><path d="M32 29.5s8.5-4 6.03-9.65C34.15 14 25 18 22.5 24.5l.01 2.1-.01-2.1C20 18 9.906 14 6.997 19.85c-2.497 5.65 4.853 9 4.853 9" stroke="#ececec"/><path d="M11.5 30c5.5-3 15.5-3 21 0m-21 3.5c5.5-3 15.5-3 21 0m-21 3.5c5.5-3 15.5-3 21 0" stroke="#ececec"/></g>',
|
||||
bQ: '<g fill-rule="evenodd" stroke="#000" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><g stroke="none"><circle cx="6" cy="12" r="2.75"/><circle cx="14" cy="9" r="2.75"/><circle cx="22.5" cy="8" r="2.75"/><circle cx="31" cy="9" r="2.75"/><circle cx="39" cy="12" r="2.75"/></g><path d="M9 26c8.5-1.5 21-1.5 27 0l2.5-12.5L31 25l-.3-14.1-5.2 13.6-3-14.5-3 14.5-5.2-13.6L14 25 6.5 13.5 9 26z" stroke-linecap="butt"/><path d="M9 26c0 2 1.5 2 2.5 4 1 1.5 1 1 .5 3.5-1.5 1-1.5 2.5-1.5 2.5-1.5 1.5.5 2.5.5 2.5 6.5 1 16.5 1 23 0 0 0 1.5-1 0-2.5 0 0 .5-1.5-1-2.5-.5-2.5-.5-2 .5-3.5 1-2 2.5-2 2.5-4-8.5-1.5-18.5-1.5-27 0z" stroke-linecap="butt"/><path d="M11 38.5a35 35 1 0 0 23 0" fill="none" stroke-linecap="butt"/><path d="M11 29a35 35 1 0 1 23 0m-21.5 2.5h20m-21 3a35 35 1 0 0 22 0m-23 3a35 35 1 0 0 24 0" fill="none" stroke="#ececec"/></g>',
|
||||
bR: '<g fill-rule="evenodd" stroke="#000" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M9 39h27v-3H9v3zm3.5-7l1.5-2.5h17l1.5 2.5h-20zm-.5 4v-4h21v4H12z" stroke-linecap="butt"/><path d="M14 29.5v-13h17v13H14z" stroke-linecap="butt" stroke-linejoin="miter"/><path d="M14 16.5L11 14h23l-3 2.5H14zM11 14V9h4v2h5V9h5v2h5V9h4v5H11z" stroke-linecap="butt"/><path d="M12 35.5h21m-20-4h19m-18-2h17m-17-13h17M11 14h23" fill="none" stroke="#ececec" stroke-width="1" stroke-linejoin="miter"/></g>',
|
||||
bB: '<g fill="none" fill-rule="evenodd" stroke="#000" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><g fill="#000" stroke-linecap="butt"><path d="M9 36c3.39-.97 10.11.43 13.5-2 3.39 2.43 10.11 1.03 13.5 2 0 0 1.65.54 3 2-.68.97-1.65.99-3 .5-3.39-.97-10.11.46-13.5-1-3.39 1.46-10.11.03-13.5 1-1.354.49-2.323.47-3-.5 1.354-1.94 3-2 3-2z"/><path d="M15 32c2.5 2.5 12.5 2.5 15 0 .5-1.5 0-2 0-2 0-2.5-2.5-4-2.5-4 5.5-1.5 6-11.5-5-15.5-11 4-10.5 14-5 15.5 0 0-2.5 1.5-2.5 4 0 0-.5.5 0 2z"/><path d="M25 8a2.5 2.5 0 1 1-5 0 2.5 2.5 0 1 1 5 0z"/></g><path d="M17.5 26h10M15 30h15m-7.5-14.5v5M20 18h5" stroke="#ececec" stroke-linejoin="miter"/></g>',
|
||||
bN: '<g fill="none" fill-rule="evenodd" stroke="#000" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"><path d="M22 10c10.5 1 16.5 8 16 29H15c0-9 10-6.5 8-21" fill="#000"/><path d="M24 18c.38 2.91-5.55 7.37-8 9-3 2-2.82 4.34-5 4-1.042-.94 1.41-3.04 0-3-1 0 .19 1.23-1 2-1 0-4.003 1-4-4 0-2 6-12 6-12s1.89-1.9 2-3.5c-.73-.994-.5-2-.5-3 1-1 3 2.5 3 2.5h2s.78-1.992 2.5-3c1 0 1 3 1 3" fill="#000"/><path d="M9.5 25.5a.5.5 0 1 1-1 0 .5.5 0 1 1 1 0zm5.433-9.75a.5 1.5 30 1 1-.866-.5.5 1.5 30 1 1 .866.5z" fill="#ececec" stroke="#ececec"/><path d="M24.55 10.4l-.45 1.45.5.15c3.15 1 5.65 2.49 7.9 6.75S35.75 29.06 35.25 39l-.05.5h2.25l.05-.5c.5-10.06-.88-16.85-3.25-21.34-2.37-4.49-5.79-6.64-9.19-7.16l-.51-.1z" fill="#ececec" stroke="none"/></g>',
|
||||
bP: '<path d="M22.5 9c-2.21 0-4 1.79-4 4 0 .89.29 1.71.78 2.38C17.33 16.5 16 18.59 16 21c0 2.03.94 3.84 2.41 5.03-3 1.06-7.41 5.55-7.41 13.47h23c0-7.92-4.41-12.41-7.41-13.47 1.47-1.19 2.41-3 2.41-5.03 0-2.41-1.33-4.5-3.28-5.62.49-.67.78-1.49.78-2.38 0-2.21-1.79-4-4-4z" stroke="#000" stroke-width="1.5" stroke-linecap="round"/>'
|
||||
};
|
||||
|
||||
function buildSprite() {
|
||||
|
||||
if ($('bd-sprite')) return;
|
||||
|
||||
var defs = '';
|
||||
Object.keys(PIECES).forEach(function (key) {
|
||||
defs += '<g id="bd-p-' + key + '">' + PIECES[key] + '</g>';
|
||||
});
|
||||
|
||||
var sprite = document.createElementNS(NS, 'svg');
|
||||
sprite.setAttribute('id', 'bd-sprite');
|
||||
sprite.setAttribute('width', '0');
|
||||
sprite.setAttribute('height', '0');
|
||||
sprite.setAttribute('aria-hidden', 'true');
|
||||
sprite.style.position = 'absolute';
|
||||
sprite.innerHTML = '<defs>' + defs + '</defs>';
|
||||
|
||||
document.body.appendChild(sprite);
|
||||
}
|
||||
|
||||
function pieceKey(piece) {
|
||||
return (piece === piece.toUpperCase() ? 'w' : 'b') + piece.toUpperCase();
|
||||
}
|
||||
|
||||
/* ---------- The board ---------- */
|
||||
|
||||
// Top left corner of a square, in the 800 x 800 space of the board
|
||||
function corner(square) {
|
||||
|
||||
var file = square & 7, rank = square >> 3;
|
||||
|
||||
return flipped ? { x: (7 - file) * 100, y: rank * 100 } : { x: file * 100, y: (7 - rank) * 100 };
|
||||
}
|
||||
|
||||
function centre(square) {
|
||||
var at = corner(square);
|
||||
return { x: at.x + 50, y: at.y + 50 };
|
||||
}
|
||||
|
||||
function arrow(from, to, className) {
|
||||
|
||||
var a = centre(from), b = centre(to);
|
||||
var dx = b.x - a.x, dy = b.y - a.y, length = Math.sqrt(dx * dx + dy * dy);
|
||||
|
||||
if (!length) return '';
|
||||
|
||||
var ux = dx / length, uy = dy / length;
|
||||
var tip = { x: b.x - ux * 8, y: b.y - uy * 8 };
|
||||
var base = { x: tip.x - ux * 42, y: tip.y - uy * 42 };
|
||||
var from_ = { x: a.x + ux * 22, y: a.y + uy * 22 };
|
||||
|
||||
var points = [
|
||||
tip.x + ',' + tip.y,
|
||||
(base.x - uy * 25) + ',' + (base.y + ux * 25),
|
||||
(base.x + uy * 25) + ',' + (base.y - ux * 25)
|
||||
].join(' ');
|
||||
|
||||
return '<g class="' + className + '">' +
|
||||
'<line x1="' + from_.x + '" y1="' + from_.y + '" x2="' + (base.x + ux * 2) + '" y2="' + (base.y + uy * 2) + '" stroke-width="15"/>' +
|
||||
'<polygon points="' + points + '"/></g>';
|
||||
}
|
||||
|
||||
function square(at, className) {
|
||||
return '<rect class="' + className + '" x="' + at.x + '" y="' + at.y + '" width="100" height="100"/>';
|
||||
}
|
||||
|
||||
function drawBoard(position, index) {
|
||||
|
||||
var out = '<svg viewBox="0 0 800 800" role="img" aria-label="Chess board"><defs>' +
|
||||
'<radialGradient id="bd-check"><stop offset="0" class="bd-check-in"/><stop offset="0.75" class="bd-check-out"/></radialGradient></defs>';
|
||||
|
||||
var file, rank, at, s;
|
||||
|
||||
for (rank = 0; rank < 8; rank++) {
|
||||
for (file = 0; file < 8; file++) {
|
||||
at = corner(rank * 8 + file);
|
||||
out += square(at, 'bd-sq ' + ((file + rank) % 2 === 0 ? 'bd-dark' : 'bd-light'));
|
||||
}
|
||||
}
|
||||
|
||||
if (position.from >= 0) {
|
||||
out += square(corner(position.from), 'bd-hl bd-hl-from');
|
||||
out += square(corner(position.to), 'bd-hl bd-hl-to');
|
||||
}
|
||||
|
||||
if (position.check >= 0) {
|
||||
at = corner(position.check);
|
||||
out += '<rect fill="url(#bd-check)" x="' + at.x + '" y="' + at.y + '" width="100" height="100"/>';
|
||||
}
|
||||
|
||||
var showAttempt = attempt && index === total && !problem;
|
||||
|
||||
if (showAttempt) {
|
||||
out += square(corner(attempt.from), 'bd-hl bd-hl-bad');
|
||||
out += square(corner(attempt.to), 'bd-hl bd-hl-bad');
|
||||
}
|
||||
|
||||
// Coordinates sit inside the squares along the bottom and left edges
|
||||
var bottom = flipped ? 7 : 0, left = flipped ? 7 : 0;
|
||||
|
||||
for (file = 0; file < 8; file++) {
|
||||
s = bottom * 8 + file;
|
||||
at = corner(s);
|
||||
out += '<text class="bd-coord ' + (((file + bottom) % 2 === 0) ? 'on-dark' : 'on-light') +
|
||||
'" x="' + (at.x + 93) + '" y="' + (at.y + 91) + '" text-anchor="end">' + 'abcdefgh'.charAt(file) + '</text>';
|
||||
}
|
||||
|
||||
for (rank = 0; rank < 8; rank++) {
|
||||
s = rank * 8 + left;
|
||||
at = corner(s);
|
||||
out += '<text class="bd-coord ' + (((left + rank) % 2 === 0) ? 'on-dark' : 'on-light') +
|
||||
'" x="' + (at.x + 7) + '" y="' + (at.y + 20) + '">' + (rank + 1) + '</text>';
|
||||
}
|
||||
|
||||
for (s = 0; s < 64; s++) {
|
||||
var piece = position.board.charAt(s);
|
||||
if (piece === '.') continue;
|
||||
at = corner(s);
|
||||
out += '<use href="#bd-p-' + pieceKey(piece) + '" transform="translate(' + at.x + ' ' + at.y + ') scale(2.2222)"/>';
|
||||
}
|
||||
|
||||
if (showAttempt) out += arrow(attempt.from, attempt.to, 'bd-arrow');
|
||||
|
||||
return out + '</svg>';
|
||||
}
|
||||
|
||||
/* ---------- Player strips, captured pieces, material ---------- */
|
||||
|
||||
var ORDER = { q: 0, r: 1, b: 2, n: 3, p: 4 };
|
||||
|
||||
function captured(list) {
|
||||
|
||||
return list.split('').sort(function (a, b) {
|
||||
return ORDER[a.toLowerCase()] - ORDER[b.toLowerCase()];
|
||||
}).map(function (piece) {
|
||||
return '<svg class="bd-cap" viewBox="0 0 45 45" aria-hidden="true"><use href="#bd-p-' + pieceKey(piece) + '"/></svg>';
|
||||
}).join('');
|
||||
}
|
||||
|
||||
function fillStrip(strip, color, position) {
|
||||
|
||||
if (!strip) return;
|
||||
|
||||
var other = color === 'w' ? 'b' : 'w';
|
||||
var material = Chess.material(position.board);
|
||||
var lead = material[color] - material[other];
|
||||
|
||||
strip.className = 'bd-player is-' + (color === 'w' ? 'white' : 'black') + (position.turn === color ? ' is-turn' : '');
|
||||
strip.querySelector('.bd-name').textContent = color === 'w' ? game.white : game.black;
|
||||
strip.querySelector('.bd-caps').innerHTML = captured(position.caps[color]);
|
||||
strip.querySelector('.bd-mat').textContent = lead > 0 ? '+' + lead : '';
|
||||
}
|
||||
|
||||
function describe(position, index) {
|
||||
|
||||
if (problem && index > positions.length - 1) {
|
||||
return { tone: 'warn', text: 'Move ' + (problem.ply + 1) + ' (' + problem.san + ') cannot be played on the board' };
|
||||
}
|
||||
|
||||
if (position.status === 'checkmate') return { tone: 'bad', text: 'Checkmate' };
|
||||
if (position.status === 'stalemate') return { tone: 'warn', text: 'Stalemate' };
|
||||
|
||||
if (attempt && index === total) {
|
||||
return { tone: 'bad', text: (position.turn === 'w' ? 'White' : 'Black') + ' tried ' + attempt.text + ', which is illegal' };
|
||||
}
|
||||
|
||||
return { tone: position.check >= 0 ? 'warn' : '', text: (position.check >= 0 ? 'Check. ' : '') + (position.turn === 'w' ? 'White' : 'Black') + ' to move' };
|
||||
}
|
||||
|
||||
/* ---------- Evaluation bar ---------- */
|
||||
|
||||
function drawEval(index) {
|
||||
|
||||
var bar = $('bd-eval');
|
||||
if (!bar) return;
|
||||
|
||||
var info = evals[Math.min(index, evals.length - 1)];
|
||||
var share = info.value === null ? 50 : 50 + 50 * squash(info.value);
|
||||
var label = bar.querySelector('.bd-eval-label');
|
||||
|
||||
bar.classList.toggle('is-flipped', flipped);
|
||||
bar.querySelector('.bd-eval-fill').style.height = share + '%';
|
||||
|
||||
label.textContent = info.label;
|
||||
label.className = 'bd-eval-label ' + (info.value !== null && info.value < 0 ? 'on-black' : 'on-white');
|
||||
bar.setAttribute('title', 'Evaluation: ' + info.label);
|
||||
}
|
||||
|
||||
/* ---------- Evaluation graph ---------- */
|
||||
|
||||
var graph = { width: 600, height: 150, pad: 8, cursor: null };
|
||||
|
||||
function graphX(index) { return total ? (index / total) * graph.width : 0; }
|
||||
|
||||
function graphY(value) {
|
||||
var middle = graph.height / 2;
|
||||
return middle - squash(value) * (middle - graph.pad);
|
||||
}
|
||||
|
||||
function moveLabel(index) {
|
||||
|
||||
if (index === 0) return 'Start position';
|
||||
|
||||
var move = moves[index - 1];
|
||||
return move.num + (move.color === 'w' ? '.' : '\u2026') + ' ' + move.san;
|
||||
}
|
||||
|
||||
function buildGraph() {
|
||||
|
||||
var host = $('bd-graph');
|
||||
var card = $('bd-graph-card');
|
||||
|
||||
if (!host) return;
|
||||
|
||||
if (!hasEvals) {
|
||||
if (card) card.hidden = true;
|
||||
return;
|
||||
}
|
||||
|
||||
var middle = graph.height / 2, previous = 0, points = [], i;
|
||||
|
||||
for (i = 0; i <= total; i++) {
|
||||
if (evals[i].value !== null) previous = evals[i].value;
|
||||
points.push([graphX(i), graphY(previous)]);
|
||||
}
|
||||
|
||||
var line = points.map(function (point, n) { return (n ? 'L' : 'M') + point[0].toFixed(1) + ' ' + point[1].toFixed(1); }).join(' ');
|
||||
var area = 'M0 ' + middle + ' ' + line.replace(/^M/, 'L') + ' L' + graph.width + ' ' + middle + ' Z';
|
||||
|
||||
host.innerHTML =
|
||||
'<svg viewBox="0 0 ' + graph.width + ' ' + graph.height + '" preserveAspectRatio="none" role="img" aria-label="Evaluation graph">' +
|
||||
'<defs><clipPath id="bd-clip-top"><rect x="0" y="0" width="' + graph.width + '" height="' + middle + '"/></clipPath>' +
|
||||
'<clipPath id="bd-clip-bottom"><rect x="0" y="' + middle + '" width="' + graph.width + '" height="' + middle + '"/></clipPath></defs>' +
|
||||
'<path class="bd-area-white" d="' + area + '" clip-path="url(#bd-clip-top)"/>' +
|
||||
'<path class="bd-area-black" d="' + area + '" clip-path="url(#bd-clip-bottom)"/>' +
|
||||
'<line class="bd-mid" x1="0" y1="' + middle + '" x2="' + graph.width + '" y2="' + middle + '"/>' +
|
||||
'<path class="bd-curve" d="' + line + '"/>' +
|
||||
'<line class="bd-cursor" id="bd-cursor" x1="0" y1="0" x2="0" y2="' + graph.height + '"/></svg>';
|
||||
|
||||
graph.cursor = $('bd-cursor');
|
||||
|
||||
var scrubbing = false;
|
||||
|
||||
function indexAt(event) {
|
||||
var box = host.getBoundingClientRect();
|
||||
var ratio = box.width ? (event.clientX - box.left) / box.width : 0;
|
||||
return Math.max(0, Math.min(total, Math.round(ratio * total)));
|
||||
}
|
||||
|
||||
host.addEventListener('pointerdown', function (event) {
|
||||
scrubbing = true;
|
||||
if (host.setPointerCapture) host.setPointerCapture(event.pointerId);
|
||||
go(indexAt(event));
|
||||
});
|
||||
|
||||
host.addEventListener('pointermove', function (event) {
|
||||
var index = indexAt(event);
|
||||
graphLabel(index);
|
||||
if (scrubbing) go(index);
|
||||
});
|
||||
|
||||
host.addEventListener('pointerup', function () { scrubbing = false; });
|
||||
host.addEventListener('pointercancel', function () { scrubbing = false; });
|
||||
host.addEventListener('pointerleave', function () { if (!scrubbing) graphLabel(current); });
|
||||
}
|
||||
|
||||
function graphLabel(index) {
|
||||
var label = $('bd-graph-label');
|
||||
if (label) label.textContent = moveLabel(index) + (evals[index].label !== '\u2013' ? ' \u00B7 ' + evals[index].label : '');
|
||||
}
|
||||
|
||||
function drawGraphCursor(index) {
|
||||
|
||||
if (graph.cursor) {
|
||||
var x = graphX(index).toFixed(1);
|
||||
graph.cursor.setAttribute('x1', x);
|
||||
graph.cursor.setAttribute('x2', x);
|
||||
}
|
||||
|
||||
graphLabel(index);
|
||||
}
|
||||
|
||||
/* ---------- Putting it together ---------- */
|
||||
|
||||
function go(index) {
|
||||
|
||||
index = Math.max(0, Math.min(total, index));
|
||||
|
||||
if (window.OpenBenchViewer) window.OpenBenchViewer.select(index);
|
||||
else { current = index; render(); }
|
||||
}
|
||||
|
||||
function render() {
|
||||
|
||||
var position = positions[Math.min(current, positions.length - 1)];
|
||||
var status = describe(position, current);
|
||||
|
||||
host.innerHTML = drawBoard(position, current);
|
||||
|
||||
// The side at the bottom of the board is the one that faces us
|
||||
fillStrip($('bd-bottom'), flipped ? 'b' : 'w', position);
|
||||
fillStrip($('bd-top'), flipped ? 'w' : 'b', position);
|
||||
|
||||
drawEval(current);
|
||||
drawGraphCursor(current);
|
||||
|
||||
var note = $('bd-status');
|
||||
if (note) {
|
||||
note.textContent = status.text;
|
||||
note.className = 'bd-status' + (status.tone ? ' is-' + status.tone : '');
|
||||
}
|
||||
|
||||
var fen = $('bd-fen');
|
||||
if (fen) { fen.textContent = position.fen; fen.setAttribute('title', position.fen); }
|
||||
|
||||
[['bd-first', 0], ['bd-prev', 0], ['bd-next', total], ['bd-last', total]].forEach(function (pair) {
|
||||
if ($(pair[0])) $(pair[0]).disabled = current === pair[1];
|
||||
});
|
||||
}
|
||||
|
||||
function stop() {
|
||||
|
||||
if (timer) window.clearInterval(timer);
|
||||
timer = null;
|
||||
|
||||
var play = $('bd-play');
|
||||
if (play) {
|
||||
play.classList.remove('is-playing');
|
||||
play.setAttribute('aria-label', 'Play');
|
||||
play.innerHTML = '<i class="fa-solid fa-play"></i>';
|
||||
}
|
||||
}
|
||||
|
||||
function play() {
|
||||
|
||||
if (timer) return stop();
|
||||
|
||||
if (current >= total) go(0);
|
||||
|
||||
timer = window.setInterval(function () {
|
||||
if (current >= total) return stop();
|
||||
go(current + 1);
|
||||
}, 900);
|
||||
|
||||
var button = $('bd-play');
|
||||
if (button) {
|
||||
button.classList.add('is-playing');
|
||||
button.setAttribute('aria-label', 'Pause');
|
||||
button.innerHTML = '<i class="fa-solid fa-pause"></i>';
|
||||
}
|
||||
}
|
||||
|
||||
function flip() {
|
||||
|
||||
flipped = !flipped;
|
||||
try { window.localStorage.setItem('ob:board:flipped', flipped ? '1' : '0'); } catch (error) { /* ignore */ }
|
||||
render();
|
||||
}
|
||||
|
||||
function bind(id, handler) {
|
||||
if ($(id)) $(id).addEventListener('click', handler);
|
||||
}
|
||||
|
||||
bind('bd-first', function () { stop(); go(0); });
|
||||
bind('bd-prev', function () { stop(); go(current - 1); });
|
||||
bind('bd-next', function () { stop(); go(current + 1); });
|
||||
bind('bd-last', function () { stop(); go(total); });
|
||||
bind('bd-play', play);
|
||||
bind('bd-flip', flip);
|
||||
|
||||
bind('bd-copy', function () {
|
||||
var position = positions[Math.min(current, positions.length - 1)];
|
||||
if (window.OpenBenchViewer) window.OpenBenchViewer.copy(position.fen, 'FEN copied');
|
||||
});
|
||||
|
||||
document.addEventListener('keydown', function (event) {
|
||||
|
||||
if (event.altKey || event.ctrlKey || event.metaKey) return;
|
||||
if (/^(INPUT|TEXTAREA|SELECT|BUTTON|A)$/.test((event.target && event.target.tagName) || '')) return;
|
||||
|
||||
if (event.key === 'f' || event.key === 'F') { flip(); event.preventDefault(); }
|
||||
if (event.key === ' ') { play(); event.preventDefault(); }
|
||||
|
||||
// Moving by hand ends a running playback
|
||||
if (/^(ArrowLeft|ArrowRight|Home|End)$/.test(event.key)) stop();
|
||||
});
|
||||
|
||||
document.addEventListener('ob:ply', function (event) {
|
||||
current = event.detail.index;
|
||||
render();
|
||||
});
|
||||
|
||||
window.OpenBenchBoard = {
|
||||
flip : flip,
|
||||
play : play,
|
||||
positions : positions,
|
||||
evals : evals
|
||||
};
|
||||
|
||||
buildSprite();
|
||||
buildGraph();
|
||||
render();
|
||||
|
||||
})();
|
||||
Reference in new issue
Block a user