react-chess-replay-trainer 0.0.2 → 0.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.
- package/README.md +46 -44
- package/package.json +56 -56
- package/dist/features/replay/miss/replayMissDisplay.d.ts +0 -16
- package/dist/features/replay/miss/useReplayMissBoard.d.ts +0 -28
- package/dist/features/replay/miss/useReplayMissSequence.d.ts +0 -10
- package/dist/features/replay/miss/useReplayRefutation.d.ts +0 -3
- package/dist/features/replay/refutation/replayRefutation.d.ts +0 -19
package/README.md
CHANGED
|
@@ -1,44 +1,46 @@
|
|
|
1
|
-
# react-chess-replay-trainer
|
|
2
|
-
|
|
3
|
-
A React component for replaying a chess game move-by-move and drilling it.
|
|
4
|
-
|
|
5
|
-
- **Browse** freely through the game (first / prev / next / last / jump) without
|
|
6
|
-
recording anything, so you can pick the part of the game you want to study.
|
|
7
|
-
- **Train White / Train Black / Train Both** start a drill at the current ply:
|
|
8
|
-
you guess each move, and every mistake is reported via `onMiss` so the host can
|
|
9
|
-
(for example) enroll the missed position into a spaced-repetition deck.
|
|
10
|
-
- With **Train White** or **Train Black** you only guess that side's moves; the
|
|
11
|
-
opponent's reply is played automatically after each correct guess, and the
|
|
12
|
-
board is rotated so the trained side is on the bottom.
|
|
13
|
-
- With **Train Both** you drill every ply for both colors.
|
|
14
|
-
- **Analyze** opens the built-in analysis board (`AnalysisBoard` from
|
|
15
|
-
`react-chess-core`) at the current position.
|
|
16
|
-
|
|
17
|
-
Depends on `react-chess-core` (board, engine, analysis board), `react-chessboard`,
|
|
18
|
-
and `chess.js`.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
1
|
+
# react-chess-replay-trainer
|
|
2
|
+
|
|
3
|
+
A React component for replaying a chess game move-by-move and drilling it.
|
|
4
|
+
|
|
5
|
+
- **Browse** freely through the game (first / prev / next / last / jump) without
|
|
6
|
+
recording anything, so you can pick the part of the game you want to study.
|
|
7
|
+
- **Train White / Train Black / Train Both** start a drill at the current ply:
|
|
8
|
+
you guess each move, and every mistake is reported via `onMiss` so the host can
|
|
9
|
+
(for example) enroll the missed position into a spaced-repetition deck.
|
|
10
|
+
- With **Train White** or **Train Black** you only guess that side's moves; the
|
|
11
|
+
opponent's reply is played automatically after each correct guess, and the
|
|
12
|
+
board is rotated so the trained side is on the bottom.
|
|
13
|
+
- With **Train Both** you drill every ply for both colors.
|
|
14
|
+
- **Analyze** opens the built-in analysis board (`AnalysisBoard` from
|
|
15
|
+
`react-chess-core`) at the current position.
|
|
16
|
+
|
|
17
|
+
Depends on `react-chess-core` (board, engine, analysis board), `react-chessboard`,
|
|
18
|
+
and `chess.js`.
|
|
19
|
+
|
|
20
|
+
Used in production at [endchess.com](https://endchess.com).
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
```tsx
|
|
25
|
+
import { ReplayTrainer } from 'react-chess-replay-trainer';
|
|
26
|
+
|
|
27
|
+
<ReplayTrainer
|
|
28
|
+
gameId={gameId}
|
|
29
|
+
startFen={fenWhereUserWasBrowsing}
|
|
30
|
+
fetchGame={fetchGame}
|
|
31
|
+
onMiss={(miss) => enrollMissedPosition(miss)}
|
|
32
|
+
onExit={() => setTraining(null)}
|
|
33
|
+
theme="dark"
|
|
34
|
+
engine={{ depth: 18, multiPv: 3 }}
|
|
35
|
+
/>;
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
For a custom shell, use `useReplayTrainer` with `AnalysisBoard` from the same package:
|
|
39
|
+
|
|
40
|
+
```tsx
|
|
41
|
+
import {
|
|
42
|
+
useReplayTrainer,
|
|
43
|
+
buildReplayAnalysisContext,
|
|
44
|
+
AnalysisBoard,
|
|
45
|
+
} from 'react-chess-replay-trainer';
|
|
46
|
+
```
|
package/package.json
CHANGED
|
@@ -1,56 +1,56 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "react-chess-replay-trainer",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "React component for browsing a chess game and drilling its moves, reporting misses (uses react-chess-core for board and analysis)",
|
|
5
|
-
"license": "MIT",
|
|
6
|
-
"author": "Robert Blackwell",
|
|
7
|
-
"main": "dist/index.js",
|
|
8
|
-
"module": "dist/index.esm.js",
|
|
9
|
-
"types": "dist/index.d.ts",
|
|
10
|
-
"files": [
|
|
11
|
-
"dist"
|
|
12
|
-
],
|
|
13
|
-
"scripts": {
|
|
14
|
-
"build": "rollup -c",
|
|
15
|
-
"prepublishOnly": "npm run build",
|
|
16
|
-
"storybook": "storybook dev -p 6008",
|
|
17
|
-
"build-storybook": "storybook build"
|
|
18
|
-
},
|
|
19
|
-
"dependencies": {
|
|
20
|
-
"rollup": "^4.22.2",
|
|
21
|
-
"rollup-plugin-peer-deps-external": "^2.2.4",
|
|
22
|
-
"typescript": "^5.6.2"
|
|
23
|
-
},
|
|
24
|
-
"peerDependencies": {
|
|
25
|
-
"chess.js": "^1.0.0-beta.8",
|
|
26
|
-
"react": "^18.3.1",
|
|
27
|
-
"react-chess-core": "^0.1.1",
|
|
28
|
-
"react-chessboard": "^4.7.1"
|
|
29
|
-
},
|
|
30
|
-
"devDependencies": {
|
|
31
|
-
"@chromatic-com/storybook": "^1.9.0",
|
|
32
|
-
"@rollup/plugin-commonjs": "^26.0.1",
|
|
33
|
-
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
34
|
-
"@rollup/plugin-typescript": "^12.3.0",
|
|
35
|
-
"@storybook/addon-essentials": "^8.2.9",
|
|
36
|
-
"@storybook/addon-interactions": "^8.2.9",
|
|
37
|
-
"@storybook/addon-links": "^8.2.9",
|
|
38
|
-
"@storybook/addon-onboarding": "^8.2.9",
|
|
39
|
-
"@storybook/blocks": "^8.2.9",
|
|
40
|
-
"@storybook/preset-typescript": "^3.0.0",
|
|
41
|
-
"@storybook/react": "^8.2.9",
|
|
42
|
-
"@storybook/react-vite": "^8.2.9",
|
|
43
|
-
"@storybook/test": "^8.2.9",
|
|
44
|
-
"@types/react": "^18.3.12",
|
|
45
|
-
"@types/react-dom": "^18.3.1",
|
|
46
|
-
"@vitejs/plugin-react": "^4.3.1",
|
|
47
|
-
"chess.js": "^1.0.0-beta.8",
|
|
48
|
-
"react": "^18.3.1",
|
|
49
|
-
"react-chess-core": "^0.1.1",
|
|
50
|
-
"react-chessboard": "^4.7.1",
|
|
51
|
-
"react-dom": "^18.3.1",
|
|
52
|
-
"storybook": "^8.2.9",
|
|
53
|
-
"tslib": "^2.8.1",
|
|
54
|
-
"vite-tsconfig-paths": "^5.0.1"
|
|
55
|
-
}
|
|
56
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "react-chess-replay-trainer",
|
|
3
|
+
"version": "0.0.3",
|
|
4
|
+
"description": "React component for browsing a chess game and drilling its moves, reporting misses (uses react-chess-core for board and analysis)",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Robert Blackwell",
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"module": "dist/index.esm.js",
|
|
9
|
+
"types": "dist/index.d.ts",
|
|
10
|
+
"files": [
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "rollup -c",
|
|
15
|
+
"prepublishOnly": "npm run build",
|
|
16
|
+
"storybook": "storybook dev -p 6008",
|
|
17
|
+
"build-storybook": "storybook build"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"rollup": "^4.22.2",
|
|
21
|
+
"rollup-plugin-peer-deps-external": "^2.2.4",
|
|
22
|
+
"typescript": "^5.6.2"
|
|
23
|
+
},
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"chess.js": "^1.0.0-beta.8",
|
|
26
|
+
"react": "^18.3.1",
|
|
27
|
+
"react-chess-core": "^0.1.1",
|
|
28
|
+
"react-chessboard": "^4.7.1"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@chromatic-com/storybook": "^1.9.0",
|
|
32
|
+
"@rollup/plugin-commonjs": "^26.0.1",
|
|
33
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
34
|
+
"@rollup/plugin-typescript": "^12.3.0",
|
|
35
|
+
"@storybook/addon-essentials": "^8.2.9",
|
|
36
|
+
"@storybook/addon-interactions": "^8.2.9",
|
|
37
|
+
"@storybook/addon-links": "^8.2.9",
|
|
38
|
+
"@storybook/addon-onboarding": "^8.2.9",
|
|
39
|
+
"@storybook/blocks": "^8.2.9",
|
|
40
|
+
"@storybook/preset-typescript": "^3.0.0",
|
|
41
|
+
"@storybook/react": "^8.2.9",
|
|
42
|
+
"@storybook/react-vite": "^8.2.9",
|
|
43
|
+
"@storybook/test": "^8.2.9",
|
|
44
|
+
"@types/react": "^18.3.12",
|
|
45
|
+
"@types/react-dom": "^18.3.1",
|
|
46
|
+
"@vitejs/plugin-react": "^4.3.1",
|
|
47
|
+
"chess.js": "^1.0.0-beta.8",
|
|
48
|
+
"react": "^18.3.1",
|
|
49
|
+
"react-chess-core": "^0.1.1",
|
|
50
|
+
"react-chessboard": "^4.7.1",
|
|
51
|
+
"react-dom": "^18.3.1",
|
|
52
|
+
"storybook": "^8.2.9",
|
|
53
|
+
"tslib": "^2.8.1",
|
|
54
|
+
"vite-tsconfig-paths": "^5.0.1"
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export type MissSequencePhase = 'wrong' | 'refutation' | 'answer' | 'retry';
|
|
2
|
-
export type MissSequenceState = {
|
|
3
|
-
setupFen: string;
|
|
4
|
-
attemptedUci: string;
|
|
5
|
-
phase: MissSequencePhase;
|
|
6
|
-
};
|
|
7
|
-
export type ReplayMissDisplay = {
|
|
8
|
-
fen: string | null;
|
|
9
|
-
arrows: [string, string, string][];
|
|
10
|
-
animating: boolean;
|
|
11
|
-
};
|
|
12
|
-
export declare const REPLAY_MISS_WRONG_PAUSE_MS = 450;
|
|
13
|
-
export declare const REPLAY_MISS_REFUTATION_PAUSE_MS = 900;
|
|
14
|
-
export declare const REPLAY_MISS_REFUTATION_MAX_WAIT_MS = 4000;
|
|
15
|
-
export declare const REPLAY_MISS_MOVE_ANIMATION_MS = 220;
|
|
16
|
-
export declare function getReplayMissDisplay(sequence: MissSequenceState | null, expectedUci: string | null, refutationUci: string | null, answerArrowColor: string): ReplayMissDisplay;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { AnalysisEngineOptions } from 'react-chess-core';
|
|
2
|
-
type ReplayMissFeedback = 'correct' | 'incorrect' | null;
|
|
3
|
-
export declare function useReplayMissBoard({ feedback, expectedUci, positionFen, answerArrowColor, autoShowWrongMoves, engineOptions, }: {
|
|
4
|
-
feedback: ReplayMissFeedback;
|
|
5
|
-
expectedUci: string | null;
|
|
6
|
-
positionFen: string;
|
|
7
|
-
answerArrowColor: string;
|
|
8
|
-
autoShowWrongMoves?: boolean;
|
|
9
|
-
engineOptions?: AnalysisEngineOptions;
|
|
10
|
-
}): {
|
|
11
|
-
missSequence: {
|
|
12
|
-
sequence: import("./replayMissDisplay").MissSequenceState | null;
|
|
13
|
-
refutation: import("..").ReplayRefutationResult;
|
|
14
|
-
display: import("./replayMissDisplay").ReplayMissDisplay;
|
|
15
|
-
startSequence: (setupFen: string, attemptedUci: string) => void;
|
|
16
|
-
clearSequence: () => void;
|
|
17
|
-
};
|
|
18
|
-
refutation: import("..").ReplayRefutationResult;
|
|
19
|
-
customArrows: [string, string, string][];
|
|
20
|
-
boardPosition: string;
|
|
21
|
-
boardAnimating: boolean;
|
|
22
|
-
wrapDropHandler: (onDrop: (source: string, target: string, piece: string) => boolean, { enabled, dropFen, expectedMoveUci, }: {
|
|
23
|
-
enabled: boolean;
|
|
24
|
-
dropFen?: string;
|
|
25
|
-
expectedMoveUci?: string | null;
|
|
26
|
-
}) => (source: string, target: string, piece: string) => boolean;
|
|
27
|
-
};
|
|
28
|
-
export {};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { AnalysisEngineOptions } from 'react-chess-core';
|
|
2
|
-
import { type MissSequencePhase, type MissSequenceState, type ReplayMissDisplay } from './replayMissDisplay';
|
|
3
|
-
export type { MissSequencePhase, ReplayMissDisplay };
|
|
4
|
-
export declare function useReplayMissSequence(feedback: 'correct' | 'incorrect' | null, expectedUci: string | null, engineOptions: AnalysisEngineOptions, answerArrowColor: string, autoShowWrongMoves: boolean): {
|
|
5
|
-
sequence: MissSequenceState | null;
|
|
6
|
-
refutation: import("..").ReplayRefutationResult;
|
|
7
|
-
display: ReplayMissDisplay;
|
|
8
|
-
startSequence: (setupFen: string, attemptedUci: string) => void;
|
|
9
|
-
clearSequence: () => void;
|
|
10
|
-
};
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { type AnalysisEngineOptions } from 'react-chess-core';
|
|
2
|
-
import { type ReplayRefutationResult } from '../refutation/replayRefutation';
|
|
3
|
-
export declare function useReplayRefutation(setupFen: string | null, attemptedUci: string | null, expectedUci: string | null, enabled: boolean, engineOptions: AnalysisEngineOptions): ReplayRefutationResult;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { type AnalysisEngineOptions, type EngineEvaluation, type EngineLine } from 'react-chess-core';
|
|
2
|
-
/** Minimum eval loss (pawns) from the wrong move before showing a refutation. */
|
|
3
|
-
export declare const REPLAY_REFUTATION_EVAL_GAP_PAWNS = 0.5;
|
|
4
|
-
export declare const REPLAY_REFUTATION_EVAL_GAP_CP: number;
|
|
5
|
-
export type ReplayRefutationResult = {
|
|
6
|
-
fenAfterWrong: string | null;
|
|
7
|
-
refutationUci: string | null;
|
|
8
|
-
refutationSan: string | null;
|
|
9
|
-
refutationLine: string | null;
|
|
10
|
-
loading: boolean;
|
|
11
|
-
error: string | null;
|
|
12
|
-
};
|
|
13
|
-
export declare const replayRefutationEngineOptions: AnalysisEngineOptions;
|
|
14
|
-
export declare function fenAfterUci(fen: string, uci: string): string | null;
|
|
15
|
-
/** Centipawn score from side to move, comparable across sibling positions. */
|
|
16
|
-
export declare function lineEvalCpForGap(line: EngineLine | undefined): number | null;
|
|
17
|
-
/** How much better the opponent's eval is after the wrong move vs the correct one. */
|
|
18
|
-
export declare function refutationEvalGapCp(evalAfterWrong: EngineEvaluation, evalAfterCorrect: EngineEvaluation): number | null;
|
|
19
|
-
export declare function refutationFromEvaluation(fenAfterWrong: string, evaluation: EngineEvaluation, evalGapCp: number | null, evalGapApplies: boolean, evalGapLoading: boolean): Omit<ReplayRefutationResult, 'fenAfterWrong'>;
|