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:
+10
-5
@@ -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" }]);
|
||||
|
||||
Reference in New Issue
Block a user