Skip to content

Commit

Permalink
fix puzzles with multiple solutions
Browse files Browse the repository at this point in the history
  • Loading branch information
franciscoBSalgueiro committed Jan 8, 2024
1 parent 9d5c35c commit 70b4c11
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/components/puzzles/PuzzleBoard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 70b4c11

Please sign in to comment.