@react-chess-tools/react-chess-puzzle 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -35,6 +35,7 @@ export type Action =
35
35
  move?: Move | null;
36
36
  puzzleContext: ChessPuzzleContextType;
37
37
  game: Chess;
38
+ solveOnCheckmate?: boolean;
38
39
  };
39
40
  }
40
41
  | { type: "MARK_SOLVE_INVOKED" }
@@ -96,7 +97,18 @@ export const reducer = (state: State, action: Action): State => {
96
97
  };
97
98
 
98
99
  case "PLAYER_MOVE": {
99
- const { move } = action.payload;
100
+ const { move, game, solveOnCheckmate } = action.payload;
101
+
102
+ if (move && solveOnCheckmate !== false && game.isCheckmate()) {
103
+ return {
104
+ ...state,
105
+ status: "solved",
106
+ nextMove: null,
107
+ hint: "none",
108
+ isPlayerTurn: false,
109
+ onSolveInvoked: false,
110
+ };
111
+ }
100
112
 
101
113
  const isMoveRight = [move?.san, move?.lan].includes(
102
114
  state?.nextMove || "",
@@ -21,6 +21,7 @@ export const useChessPuzzle = (
21
21
  puzzle: Puzzle,
22
22
  onSolve?: (puzzleContext: ChessPuzzleContextType) => void,
23
23
  onFail?: (puzzleContext: ChessPuzzleContextType) => void,
24
+ solveOnCheckmate: boolean = true,
24
25
  ): ChessPuzzleContextType => {
25
26
  const gameContext = useChessGameContext();
26
27
 
@@ -111,6 +112,7 @@ export const useChessPuzzle = (
111
112
  move: gameContext?.game?.history({ verbose: true })?.pop() ?? null,
112
113
  puzzleContext,
113
114
  game: game,
115
+ solveOnCheckmate,
114
116
  },
115
117
  });
116
118
 
@@ -1,5 +1,5 @@
1
1
  import { type Color, Chess, Move } from "chess.js";
2
- import React, { CSSProperties, ReactElement, ReactNode } from "react";
2
+ import { type CSSProperties } from "react";
3
3
  import _ from "lodash";
4
4
  import type { ChessPuzzleTheme } from "../theme/types";
5
5
  import { defaultPuzzleTheme } from "../theme/defaults";