feat(ui): eval bar as two opposing bars (black on top, white on bottom)

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.
This commit is contained in:
ai-chess
2026-05-14 23:55:33 +03:00
parent 6f4525d59f
commit 3a9ba2ea49
2 changed files with 35 additions and 14 deletions
+10 -5
View File
@@ -131,18 +131,23 @@ function renderStatus() {
function applyEval(e) { function applyEval(e) {
const cp = e.cp, mate = e.mate; 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; let pct = 50;
if (mate != null) { if (mate != null) {
pct = mate > 0 ? 100 : 0; pct = mate > 0 ? 100 : 0;
txt.textContent = `#${mate}`; txt.textContent = (mate > 0 ? "+M" : "-M") + Math.abs(mate);
} else if (cp != null) { } else if (cp != null) {
pct = Math.max(0, Math.min(100, 50 + cp / 20)); // map cp to percentage: ±800cp = full bar. Capped.
txt.textContent = (cp / 100).toFixed(2); pct = Math.max(2, Math.min(98, 50 + cp / 16));
const v = (cp / 100);
txt.textContent = (v > 0 ? "+" : "") + v.toFixed(2);
} else { } else {
txt.textContent = "—"; 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) { if (e.best_uci && e.best_uci.length >= 4) {
const from = e.best_uci.slice(0, 2), to = e.best_uci.slice(2, 4); const from = e.best_uci.slice(0, 2), to = e.best_uci.slice(2, 4);
cg.setShapes([{ orig: from, dest: to, brush: "green" }]); cg.setShapes([{ orig: from, dest: to, brush: "green" }]);
+25 -9
View File
@@ -61,22 +61,38 @@ body {
.bubble-body { font-size: 12.5px; } .bubble-body { font-size: 12.5px; }
.bubble-empty { font-style: italic; opacity: 0.55; } .bubble-empty { font-style: italic; opacity: 0.55; }
/* ----- eval bar ----- */ /* ----- eval bar (lichess-style two-bar) ----- */
#eval-col { #eval-col {
position: relative; position: relative;
background: #18181c; background: #2a2a30; /* the BLACK half — sits at the top */
border-radius: 4px; border-radius: 4px;
overflow: hidden; overflow: hidden;
box-shadow: inset 0 0 0 1px #3a3a40;
} }
#eval-fill { /* center reference line (50/50) */
position: absolute; left: 0; right: 0; bottom: 50%; #eval-col::after {
background: linear-gradient(180deg, #fafafa 0%, #ddd 100%); content: "";
transition: bottom 0.4s ease; 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 { #eval-text {
position: absolute; left: 0; right: 0; top: 50%; transform: translateY(-50%); position: absolute; left: 0; right: 0; bottom: 4px;
text-align: center; font-size: 10px; color: #888; text-align: center; font-size: 10px;
background: rgba(20,20,24,0.6); padding: 2px 0; 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 ----- */ /* ----- board ----- */