From 70b4c11802bcbf86998fe39d643baed485b4192d Mon Sep 17 00:00:00 2001 From: Francisco Salgueiro Date: Mon, 8 Jan 2024 10:33:19 +0000 Subject: [PATCH] fix puzzles with multiple solutions --- src/components/puzzles/PuzzleBoard.tsx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/components/puzzles/PuzzleBoard.tsx b/src/components/puzzles/PuzzleBoard.tsx index 2d92d84a..351269ae 100644 --- a/src/components/puzzles/PuzzleBoard.tsx +++ b/src/components/puzzles/PuzzleBoard.tsx @@ -6,7 +6,7 @@ import { chessboard } from "@/styles/Chessboard.css"; import { Chessground } from "@/chessground/Chessground"; import { useAtomValue } from "jotai"; import { showCoordinatesAtom } from "@/atoms/atoms"; -import { Chess, NormalMove, makeUci, parseSquare } from "chessops"; +import { Chess, NormalMove, makeUci, parseSquare, parseUci } from "chessops"; import { parseFen, parsePiece } from "chessops/fen"; import { chessgroundDests } from "chessops/compat"; import { @@ -79,7 +79,14 @@ function PuzzleBoard({ const showCoordinates = useAtomValue(showCoordinatesAtom); function checkMove(move: string) { - if (puzzle && puzzle.moves[currentMove] === move) { + console.log(pos, move); + if (!pos) return; + const newPos = pos.clone(); + newPos.play(parseUci(move)!); + if ( + puzzle && + (puzzle.moves[currentMove] === move || newPos.isCheckmate()) + ) { if (currentMove === puzzle.moves.length - 1) { if (puzzle.completion !== "incorrect") { changeCompletion("correct");