diff --git a/src/components/engines/EnginesPage.tsx b/src/components/engines/EnginesPage.tsx index 67144fc0..aaff8290 100644 --- a/src/components/engines/EnginesPage.tsx +++ b/src/components/engines/EnginesPage.tsx @@ -284,7 +284,6 @@ function EngineSettings({ } else { newSettings.push({ name, value }); } - console.log(name, value, def); if (value !== def || requiredEngineSettings.includes(name)) { setEngine({ ...engine, diff --git a/src/components/panels/analysis/TablebaseInfo.tsx b/src/components/panels/analysis/TablebaseInfo.tsx index d7d800f2..6d0cdc89 100644 --- a/src/components/panels/analysis/TablebaseInfo.tsx +++ b/src/components/panels/analysis/TablebaseInfo.tsx @@ -1,5 +1,5 @@ import { TreeDispatchContext } from "@/components/common/TreeStateContext"; -import { getTablebaseInfo } from "@/utils/lichess"; +import { TablebaseCategory, getTablebaseInfo } from "@/utils/lichess"; import { Accordion, Badge, @@ -56,7 +56,7 @@ function TablebaseInfo({ {isLoading && Loading...} {error && Error: {error.message}} {data && ( - + )} @@ -82,9 +82,10 @@ function TablebaseInfo({ {m.san} @@ -100,38 +101,55 @@ function TablebaseInfo({ } function OutcomeBadge({ - outcome, + category, turn, wins, + dtz, + dtm, }: { - outcome: "win" | "loss" | "draw" | "unknown"; + category: TablebaseCategory; turn: "white" | "black"; - wins: boolean; + wins?: boolean; + dtz?: number; + dtm?: number; }) { - const color = match(outcome) + const normalizedCategory = match(category) + .with("win", () => (turn === "white" ? "White wins" : "Black wins")) + .with("loss", () => (turn === "white" ? "Black wins" : "White wins")) + .with("draw", () => "draw") + .with("blessed-loss", () => "draw") + .with("cursed-win", () => "draw") + .with("maybe-loss", () => "unknown") + .with("maybe-win", () => "unknown") + .with("unknown", () => "unknown") + .exhaustive(); + + const color = match(category) .with("win", () => (turn === "white" ? "white" : "black")) .with("loss", () => (turn === "white" ? "black" : "white")) - .with("draw", () => "gray") - .with("unknown", () => "gray") - .exhaustive(); - const label = match(outcome) - .with( - "win", - () => (turn === "white" ? "White" : "Black") + (wins ? " wins" : ""), - ) - .with( - "loss", - () => (turn === "white" ? "Black" : "White") + (wins ? " wins" : ""), - ) - .with("draw", () => "Draw") - .with("unknown", () => "Unknown") - .exhaustive(); + .otherwise(() => "gray"); + + const label = wins + ? normalizedCategory + : match(category) + .with("draw", () => "Draw") + .with("unknown", () => "Unknown") + .otherwise(() => (dtm ? `DTM ${Math.abs(dtm)}` : `DTZ ${dtz}`)); + return ( - + {label} - + {["blessed-loss", "cursed-win", "maybe-win", "maybe-loss"].includes( + category, + ) && + wins && ( + + *due to the 50-move rule + + )} + ); } diff --git a/src/utils/lichess.tsx b/src/utils/lichess.tsx index 617f4061..c427555c 100644 --- a/src/utils/lichess.tsx +++ b/src/utils/lichess.tsx @@ -24,6 +24,16 @@ const baseURL = "https://lichess.org/api"; const explorerURL = "https://explorer.lichess.ovh"; const tablebaseURL = "https://tablebase.lichess.ovh"; +export type TablebaseCategory = + | "win" + | "unknown" + | "maybe-win" + | "cursed-win" + | "draw" + | "blessed-loss" + | "maybe-loss" + | "loss"; + type TablebaseData = { checkmate: boolean; stalemate: boolean; @@ -33,11 +43,11 @@ type TablebaseData = { dtz: number; precise_dtz: number; dtm: number; - category: "win" | "loss" | "draw" | "unknown"; + category: TablebaseCategory; moves: TablebaseMove[]; }; -type TablebaseMove = { +export type TablebaseMove = { uci: string; san: string; zeroing: boolean; @@ -49,7 +59,7 @@ type TablebaseMove = { dtz: number; precise_dtz: number; dtm: number; - category: "win" | "loss"; + category: TablebaseCategory; }; type LichessPerf = {