From 3a9ba2ea4906e6fa36df740b3b3149e7714b5db6 Mon Sep 17 00:00:00 2001 From: ai-chess Date: Thu, 14 May 2026 23:55:33 +0300 Subject: [PATCH] feat(ui): eval bar as two opposing bars (black on top, white on bottom) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The dark container now visually represents the black share; the bottom-anchored white fill grows/shrinks with the eval. cp range ±800 maps to full bar. Mate is pinned at 100%/0% with #M text. The score label flips to the top when black is ahead so it stays inside the darker half. --- public/app.js | 15 ++++++++++----- public/style.css | 34 +++++++++++++++++++++++++--------- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/public/app.js b/public/app.js index f055e61..a0949cf 100644 --- a/public/app.js +++ b/public/app.js @@ -131,18 +131,23 @@ function renderStatus() { function applyEval(e) { const cp = e.cp, mate = e.mate; - const bar = $("eval-fill"), txt = $("eval-text"); + const col = $("eval-col"), bar = $("eval-fill"), txt = $("eval-text"); + // pct = % of the bar occupied by WHITE (bottom-anchored). + // 50 = even; >50 = white ahead; <50 = black ahead. let pct = 50; if (mate != null) { pct = mate > 0 ? 100 : 0; - txt.textContent = `#${mate}`; + txt.textContent = (mate > 0 ? "+M" : "-M") + Math.abs(mate); } else if (cp != null) { - pct = Math.max(0, Math.min(100, 50 + cp / 20)); - txt.textContent = (cp / 100).toFixed(2); + // map cp to percentage: ±800cp = full bar. Capped. + pct = Math.max(2, Math.min(98, 50 + cp / 16)); + const v = (cp / 100); + txt.textContent = (v > 0 ? "+" : "") + v.toFixed(2); } else { txt.textContent = "—"; } - bar.style.bottom = `${100 - pct}%`; + bar.style.height = `${pct}%`; + col.classList.toggle("advantage-black", pct < 50); if (e.best_uci && e.best_uci.length >= 4) { const from = e.best_uci.slice(0, 2), to = e.best_uci.slice(2, 4); cg.setShapes([{ orig: from, dest: to, brush: "green" }]); diff --git a/public/style.css b/public/style.css index e2cd905..4ccac49 100644 --- a/public/style.css +++ b/public/style.css @@ -61,22 +61,38 @@ body { .bubble-body { font-size: 12.5px; } .bubble-empty { font-style: italic; opacity: 0.55; } -/* ----- eval bar ----- */ +/* ----- eval bar (lichess-style two-bar) ----- */ #eval-col { position: relative; - background: #18181c; + background: #2a2a30; /* the BLACK half — sits at the top */ border-radius: 4px; overflow: hidden; + box-shadow: inset 0 0 0 1px #3a3a40; } -#eval-fill { - position: absolute; left: 0; right: 0; bottom: 50%; - background: linear-gradient(180deg, #fafafa 0%, #ddd 100%); - transition: bottom 0.4s ease; +/* center reference line (50/50) */ +#eval-col::after { + content: ""; + position: absolute; + left: 0; right: 0; top: 50%; + height: 1px; background: rgba(255,255,255,0.12); + pointer-events: none; z-index: 2; +} +#eval-fill { /* the WHITE half — anchored at bottom */ + position: absolute; + left: 0; right: 0; bottom: 0; + height: 50%; + background: linear-gradient(180deg, #fafafa 0%, #e0ddd5 100%); + transition: height 0.4s ease; + z-index: 1; } #eval-text { - position: absolute; left: 0; right: 0; top: 50%; transform: translateY(-50%); - text-align: center; font-size: 10px; color: #888; - background: rgba(20,20,24,0.6); padding: 2px 0; + position: absolute; left: 0; right: 0; bottom: 4px; + text-align: center; font-size: 10px; + color: #18181c; mix-blend-mode: difference; z-index: 3; + font-weight: 700; letter-spacing: 0.04em; +} +#eval-col.advantage-black #eval-text { + bottom: auto; top: 4px; /* flip text to top when black is ahead */ } /* ----- board ----- */