Merge branch 'master' of https://git.sistav.com/sistav/Chess
This commit is contained in:
commit
e548f80e38
2 files changed
+7
-20
No files matched your search
@@ -1,11 +1,9 @@
|
||||
// Mirrors MATE_SCORE_CP in app/analysis.py: mate in N plies arrives as ±(100000 − N).
|
||||
const MATE_SCORE_CP = 100000;
|
||||
|
||||
// CBurnett piece set by Colin M.L. Burnett (GPLv2+/BSD/CC BY-SA),
|
||||
// via https://github.com/lichess-org/lila/tree/master/public/piece/cburnett
|
||||
const PIECE_IMAGE_DIR = "/static/pieces";
|
||||
|
||||
// Classic traffic-light classification colors (for arrows on the board).
|
||||
const CLASS_COLORS = {
|
||||
best: "#3fae5b",
|
||||
good: "#7fbf5f",
|
||||
@@ -53,7 +51,7 @@ function formatEval(cp) {
|
||||
|
||||
function renderBoard(fen, flip) {
|
||||
const placement = fen.split(" ")[0];
|
||||
const rows = placement.split("/"); // rows[0] = rank 8 ... rows[7] = rank 1
|
||||
const rows = placement.split("/");
|
||||
|
||||
const board = el("board");
|
||||
board.innerHTML = "";
|
||||
@@ -90,7 +88,6 @@ function renderBoard(fen, flip) {
|
||||
});
|
||||
}
|
||||
|
||||
// Center of a square (e.g. "e4") as {x, y} in a 0-100 viewBox, matching renderBoard's layout.
|
||||
function squareToXY(square, flip) {
|
||||
const file = square.charCodeAt(0) - "a".charCodeAt(0); // 0-7
|
||||
const rank = Number(square[1]); // 1-8
|
||||
|
||||
+6
-16
@@ -34,8 +34,7 @@ async function init() {
|
||||
}
|
||||
}
|
||||
|
||||
// Wraps text in an unstyled link to the game on chess.com when we have one.
|
||||
// Built with createElement/textContent — player names come from the API.
|
||||
|
||||
function gameLink(text) {
|
||||
if (!analysis.game_url) return document.createTextNode(text);
|
||||
const a = document.createElement("a");
|
||||
@@ -47,8 +46,7 @@ function gameLink(text) {
|
||||
return a;
|
||||
}
|
||||
|
||||
// Name plates hug the board: whoever owns the pieces at the top of the board
|
||||
// gets the top plate, so they follow the flip when the user played black.
|
||||
|
||||
function profileLink(username, text) {
|
||||
const a = document.createElement("a");
|
||||
a.className = "quiet-link";
|
||||
@@ -84,7 +82,6 @@ function renderSummary() {
|
||||
`;
|
||||
}
|
||||
|
||||
// Print-style annotation marks; ordinary moves go unremarked, as in a column.
|
||||
const NAG_MARKS = { best: "!", good: "", inaccuracy: "?!", mistake: "?", blunder: "??", unknown: "" };
|
||||
|
||||
function renderMoveList() {
|
||||
@@ -142,16 +139,14 @@ function showPly(ply) {
|
||||
}
|
||||
}
|
||||
|
||||
// ---- Eval graph ----
|
||||
// viewBox coordinates; the SVG scales uniformly to the board column's width.
|
||||
|
||||
const GRAPH = { W: 1000, H: 240, PAD: 10 };
|
||||
const SVG_NS = "http://www.w3.org/2000/svg";
|
||||
let graphPts = null; // [{ply, cp}], index == ply
|
||||
|
||||
// Compress evals so ±1 pawn uses most of the height and mate scores don't
|
||||
// flatten everything else (same idea as lichess's curve).
|
||||
|
||||
function evalToY(cp) {
|
||||
const v = Math.atan((cp ?? 0) / 300) / (Math.PI / 2); // -1..1, + = white better
|
||||
const v = Math.atan((cp ?? 0) / 300) / (Math.PI / 2);
|
||||
return GRAPH.PAD + ((1 - v) / 2) * (GRAPH.H - 2 * GRAPH.PAD);
|
||||
}
|
||||
|
||||
@@ -171,7 +166,6 @@ function renderEvalGraph() {
|
||||
svg.innerHTML = "";
|
||||
svg.setAttribute("viewBox", `0 0 ${GRAPH.W} ${GRAPH.H}`);
|
||||
|
||||
// Older cached analyses predate initial_eval_cp; fall back to level.
|
||||
const startCp = analysis.initial_eval_cp ?? 0;
|
||||
graphPts = [{ ply: 0, cp: startCp }];
|
||||
let lastCp = startCp;
|
||||
@@ -180,9 +174,7 @@ function renderEvalGraph() {
|
||||
graphPts.push({ ply: m.ply, cp: lastCp });
|
||||
}
|
||||
|
||||
// Ink on paper, like a stock listing: the faint shaded area is White's
|
||||
// share of the game, the ink line is the story, red dots mark the sins.
|
||||
// Colors come from the stylesheet's :root variables so the palette has one home.
|
||||
|
||||
const theme = getComputedStyle(document.documentElement);
|
||||
const PAPER = theme.getPropertyValue("--paper").trim();
|
||||
const INK = theme.getPropertyValue("--ink").trim();
|
||||
@@ -201,7 +193,6 @@ function renderEvalGraph() {
|
||||
fill: AREA,
|
||||
}));
|
||||
|
||||
// Equality midline — a solid hairline rule.
|
||||
const midY = evalToY(0);
|
||||
svg.appendChild(svgEl("line", {
|
||||
x1: 0, y1: midY, x2: GRAPH.W, y2: midY,
|
||||
@@ -221,7 +212,6 @@ function renderEvalGraph() {
|
||||
}));
|
||||
}
|
||||
|
||||
// Hover crosshair + current-position marker.
|
||||
svg.appendChild(svgEl("line", {
|
||||
id: "eval-hover-line", x1: 0, y1: 0, x2: 0, y2: GRAPH.H,
|
||||
stroke: MUTED, "stroke-width": 1.5, visibility: "hidden",
|
||||
|
||||
Reference in new issue
Block a user