From 7f944380b179f825dcbaf42842d2a791ce99d4a4 Mon Sep 17 00:00:00 2001 From: supertorpe Date: Mon, 9 Jun 2025 20:20:46 +0200 Subject: [PATCH] Show best move arrow for current position --- src/components/board/index.tsx | 18 +++++++++++++++--- src/constants.ts | 2 ++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/components/board/index.tsx b/src/components/board/index.tsx index d02404b..06bace0 100644 --- a/src/components/board/index.tsx +++ b/src/components/board/index.tsx @@ -16,7 +16,7 @@ import { Chess } from "chess.js"; import { getSquareRenderer } from "./squareRenderer"; import { CurrentPosition } from "@/types/eval"; import EvaluationBar from "./evaluationBar"; -import { CLASSIFICATION_COLORS } from "@/constants"; +import { CLASSIFICATION_COLORS, ENGINE_BEST_MOVE_COLOR } from "@/constants"; import { Player } from "@/types/game"; import PlayerHeader from "./playerHeader"; import { boardHueAtom, pieceSetAtom } from "./states"; @@ -208,9 +208,21 @@ export default function Board({ ); const customArrows: Arrow[] = useMemo(() => { + const bestCurrentMove = position?.eval?.bestMove; const bestMove = position?.lastEval?.bestMove; const moveClassification = position?.eval?.moveClassification; + const result = []; + + if (bestCurrentMove && showBestMoveArrow) { + const bestCurrentMoveArrow = [ + bestCurrentMove.slice(0, 2), + bestCurrentMove.slice(2, 4), + tinycolor(ENGINE_BEST_MOVE_COLOR).spin(-boardHue).toHexString(), + ] as Arrow; + result.push(bestCurrentMoveArrow); + } + if ( bestMove && showBestMoveArrow && @@ -227,10 +239,10 @@ export default function Board({ .toHexString(), ] as Arrow; - return [bestMoveArrow]; + result.push(bestMoveArrow); } - return []; + return result; }, [position, showBestMoveArrow, boardHue]); const SquareRenderer: CustomSquareRenderer = useMemo(() => { diff --git a/src/constants.ts b/src/constants.ts index b1cb070..f37a4fd 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -16,6 +16,8 @@ export const CLASSIFICATION_COLORS: Record = { [MoveClassification.Blunder]: "#df5353", }; +export const ENGINE_BEST_MOVE_COLOR = "#cccccc"; + export const DEFAULT_ENGINE: EngineName = EngineName.Stockfish17Lite; export const STRONGEST_ENGINE: EngineName = EngineName.Stockfish17;