feat(ui): thinking timer replaces pv text
Compact 'agent_name думает m:ss' indicator with a pulsing dot, tabular nums, lives in the same slot the stockfish PV used to occupy. Resets on new_game (white starts thinking), flips to the opponent on every move, clears on game_over / when scrubbing history. Tickers tick 1 Hz. Drops the now-unused PV stringification in applyEvalForFen.
This commit is contained in:
+53
-5
@@ -200,12 +200,11 @@ function storeEval(e) {
|
|||||||
|
|
||||||
function applyEvalForFen(fen) {
|
function applyEvalForFen(fen) {
|
||||||
const e = STATE.evalByFen.get(fenKey(fen));
|
const e = STATE.evalByFen.get(fenKey(fen));
|
||||||
const col = $("eval-col"), bar = $("eval-fill"), txt = $("eval-text"), pv = $("sf-pv");
|
const col = $("eval-col"), bar = $("eval-fill"), txt = $("eval-text");
|
||||||
if (!e) {
|
if (!e) {
|
||||||
txt.textContent = "—";
|
txt.textContent = "—";
|
||||||
pv.textContent = "";
|
|
||||||
bar.style.height = "50%";
|
bar.style.height = "50%";
|
||||||
col.classList.remove("advantage-black");
|
col.classList.remove("advantage-black", "advantage-white");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let pct = 50;
|
let pct = 50;
|
||||||
@@ -222,9 +221,44 @@ function applyEvalForFen(fen) {
|
|||||||
bar.style.height = `${pct}%`;
|
bar.style.height = `${pct}%`;
|
||||||
col.classList.toggle("advantage-black", pct < 50);
|
col.classList.toggle("advantage-black", pct < 50);
|
||||||
col.classList.toggle("advantage-white", pct > 50);
|
col.classList.toggle("advantage-white", pct > 50);
|
||||||
pv.textContent = e.pv && e.pv.length ? "pv: " + e.pv.slice(0, 6).join(" ") : "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------- thinking timer ----------
|
||||||
|
const THINK = {
|
||||||
|
startedAt: null, // ms timestamp when current side started thinking
|
||||||
|
side: null, // "white" | "black" | null
|
||||||
|
lastMs: { white: 0, black: 0 },
|
||||||
|
};
|
||||||
|
|
||||||
|
function fmtMmSs(ms) {
|
||||||
|
if (ms == null || ms < 0) return "0:00";
|
||||||
|
const s = Math.floor(ms / 1000);
|
||||||
|
return `${Math.floor(s / 60)}:${(s % 60).toString().padStart(2, "0")}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderThinking() {
|
||||||
|
const el = $("think-meter");
|
||||||
|
if (!el) return;
|
||||||
|
// No live thinking while viewing history or after game-over.
|
||||||
|
const live = STATE.viewPly === null && THINK.side && !STATE.game?.status?.result;
|
||||||
|
if (!live) {
|
||||||
|
// Show last completed move's think time when in live + game-over,
|
||||||
|
// otherwise stay quiet.
|
||||||
|
if (STATE.game?.status?.result) {
|
||||||
|
el.innerHTML = "";
|
||||||
|
} else if (STATE.viewPly !== null) {
|
||||||
|
el.innerHTML = "";
|
||||||
|
} else {
|
||||||
|
el.innerHTML = "";
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const elapsed = Date.now() - (THINK.startedAt || Date.now());
|
||||||
|
const who = agentDisplay(THINK.side);
|
||||||
|
el.innerHTML = `<span class="think-dot"></span><span class="think-who">${who}</span> думает <span class="think-time">${fmtMmSs(elapsed)}</span>`;
|
||||||
|
}
|
||||||
|
setInterval(renderThinking, 1000);
|
||||||
|
|
||||||
function applyEval(e) {
|
function applyEval(e) {
|
||||||
storeEval(e);
|
storeEval(e);
|
||||||
// If we're currently looking at this fen, refresh the visuals.
|
// If we're currently looking at this fen, refresh the visuals.
|
||||||
@@ -262,7 +296,12 @@ function connect() {
|
|||||||
if (ev.type === "new_game") {
|
if (ev.type === "new_game") {
|
||||||
STATE.game = ev.game;
|
STATE.game = ev.game;
|
||||||
STATE.viewPly = null;
|
STATE.viewPly = null;
|
||||||
|
THINK.startedAt = Date.now();
|
||||||
|
THINK.side = "white";
|
||||||
|
THINK.lastMs = { white: 0, black: 0 };
|
||||||
renderBoard(); renderChat(); renderHistory(); renderStatus();
|
renderBoard(); renderChat(); renderHistory(); renderStatus();
|
||||||
|
refreshGamesLink();
|
||||||
|
renderThinking();
|
||||||
log(`new game: ${ev.game?.id || "?"}`);
|
log(`new game: ${ev.game?.id || "?"}`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -274,8 +313,14 @@ function connect() {
|
|||||||
if (!ev.status?.result) {
|
if (!ev.status?.result) {
|
||||||
STATE.game.side_to_move = ev.side === "white" ? "black" : "white";
|
STATE.game.side_to_move = ev.side === "white" ? "black" : "white";
|
||||||
}
|
}
|
||||||
|
// think timer: mover finished, opponent starts
|
||||||
|
if (THINK.startedAt != null && THINK.side === ev.side) {
|
||||||
|
THINK.lastMs[ev.side] = Date.now() - THINK.startedAt;
|
||||||
|
}
|
||||||
|
THINK.startedAt = ev.status?.result ? null : Date.now();
|
||||||
|
THINK.side = ev.status?.result ? null : (ev.side === "white" ? "black" : "white");
|
||||||
// stay live unless user clicked back
|
// stay live unless user clicked back
|
||||||
renderBoard(); renderChat(); renderHistory(); renderStatus();
|
renderBoard(); renderChat(); renderHistory(); renderStatus(); renderThinking();
|
||||||
log(`${ev.side} ${ev.san} «${ev.comment || ""}»`);
|
log(`${ev.side} ${ev.san} «${ev.comment || ""}»`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -285,7 +330,10 @@ function connect() {
|
|||||||
STATE.game.status.result = ev.result;
|
STATE.game.status.result = ev.result;
|
||||||
STATE.game.status.termination = ev.termination;
|
STATE.game.status.termination = ev.termination;
|
||||||
}
|
}
|
||||||
|
THINK.startedAt = null;
|
||||||
|
THINK.side = null;
|
||||||
renderStatus();
|
renderStatus();
|
||||||
|
renderThinking();
|
||||||
refreshGamesLink();
|
refreshGamesLink();
|
||||||
// unlock the setup dialog if it was open and waiting
|
// unlock the setup dialog if it was open and waiting
|
||||||
try { refreshSetupGate(); } catch (e) {}
|
try { refreshSetupGate(); } catch (e) {}
|
||||||
|
|||||||
+1
-1
@@ -20,7 +20,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div id="board-footer">
|
<div id="board-footer">
|
||||||
<span id="status-line">…</span>
|
<span id="status-line">…</span>
|
||||||
<span id="sf-pv"></span>
|
<span id="think-meter"></span>
|
||||||
<button id="live-btn" hidden>live</button>
|
<button id="live-btn" hidden>live</button>
|
||||||
<a id="games-link" href="/games">games & stats</a>
|
<a id="games-link" href="/games">games & stats</a>
|
||||||
<button id="abort-game" hidden>abort game</button>
|
<button id="abort-game" hidden>abort game</button>
|
||||||
|
|||||||
+29
-1
@@ -48,7 +48,35 @@ body {
|
|||||||
font-size: 12.5px;
|
font-size: 12.5px;
|
||||||
}
|
}
|
||||||
#status-line { flex: 0 0 auto; opacity: 0.85; }
|
#status-line { flex: 0 0 auto; opacity: 0.85; }
|
||||||
#sf-pv { flex: 1; opacity: 0.5; font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
|
#think-meter {
|
||||||
|
flex: 1;
|
||||||
|
font-size: 12px;
|
||||||
|
opacity: 0.75;
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: baseline;
|
||||||
|
gap: 4px;
|
||||||
|
letter-spacing: 0.01em;
|
||||||
|
}
|
||||||
|
.think-dot {
|
||||||
|
display: inline-block;
|
||||||
|
width: 6px; height: 6px;
|
||||||
|
border-radius: 50%;
|
||||||
|
background: #c0a060;
|
||||||
|
animation: think-pulse 1.4s ease-in-out infinite;
|
||||||
|
align-self: center;
|
||||||
|
margin-right: 4px;
|
||||||
|
}
|
||||||
|
.think-who { color: #d8d4c8; font-weight: 600; }
|
||||||
|
.think-time {
|
||||||
|
font-variant-numeric: tabular-nums;
|
||||||
|
color: #f0d090;
|
||||||
|
font-weight: 600;
|
||||||
|
font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
|
||||||
|
}
|
||||||
|
@keyframes think-pulse {
|
||||||
|
0%, 100% { opacity: 0.3; transform: scale(0.9); }
|
||||||
|
50% { opacity: 1; transform: scale(1.1); }
|
||||||
|
}
|
||||||
|
|
||||||
/* ============ eval bar ============ */
|
/* ============ eval bar ============ */
|
||||||
#eval-col {
|
#eval-col {
|
||||||
|
|||||||
Reference in New Issue
Block a user