@dxos/react-ui-gameboard 0.8.4-main.c1de068 → 0.8.4-main.c85a9c8dae
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 +2 -0
- package/dist/lib/browser/index.mjs +736 -788
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +736 -788
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/components/Chessboard/Chessboard.d.ts +20 -0
- package/dist/types/src/components/Chessboard/Chessboard.d.ts.map +1 -0
- package/dist/types/src/components/Chessboard/Chessboard.stories.d.ts +30 -0
- package/dist/types/src/components/Chessboard/Chessboard.stories.d.ts.map +1 -0
- package/dist/types/src/components/Chessboard/chess.d.ts +60 -0
- package/dist/types/src/components/Chessboard/chess.d.ts.map +1 -0
- package/dist/types/src/components/Chessboard/chess.test.d.ts +2 -0
- package/dist/types/src/components/Chessboard/chess.test.d.ts.map +1 -0
- package/dist/types/src/components/Chessboard/index.d.ts.map +1 -0
- package/dist/types/src/components/Gameboard/Gameboard.d.ts +37 -0
- package/dist/types/src/components/Gameboard/Gameboard.d.ts.map +1 -0
- package/dist/types/src/{Gameboard → components/Gameboard}/Piece.d.ts +3 -2
- package/dist/types/src/components/Gameboard/Piece.d.ts.map +1 -0
- package/dist/types/src/components/Gameboard/Square.d.ts.map +1 -0
- package/dist/types/src/components/Gameboard/index.d.ts +4 -0
- package/dist/types/src/components/Gameboard/index.d.ts.map +1 -0
- package/dist/types/src/{Gameboard → components/Gameboard}/types.d.ts +3 -2
- package/dist/types/src/components/Gameboard/types.d.ts.map +1 -0
- package/dist/types/src/components/Gameboard/util.d.ts.map +1 -0
- package/dist/types/src/components/index.d.ts +3 -0
- package/dist/types/src/components/index.d.ts.map +1 -0
- package/dist/types/src/gen/pieces/chess/alpha/bB.d.ts +2 -2
- package/dist/types/src/gen/pieces/chess/alpha/bB.d.ts.map +1 -1
- package/dist/types/src/gen/pieces/chess/alpha/bK.d.ts +2 -2
- package/dist/types/src/gen/pieces/chess/alpha/bN.d.ts +2 -2
- package/dist/types/src/gen/pieces/chess/alpha/bP.d.ts +2 -2
- package/dist/types/src/gen/pieces/chess/alpha/bQ.d.ts +2 -2
- package/dist/types/src/gen/pieces/chess/alpha/bQ.d.ts.map +1 -1
- package/dist/types/src/gen/pieces/chess/alpha/bR.d.ts +2 -2
- package/dist/types/src/gen/pieces/chess/alpha/index.d.ts +12 -12
- package/dist/types/src/gen/pieces/chess/alpha/wB.d.ts +2 -2
- package/dist/types/src/gen/pieces/chess/alpha/wK.d.ts +2 -2
- package/dist/types/src/gen/pieces/chess/alpha/wN.d.ts +2 -2
- package/dist/types/src/gen/pieces/chess/alpha/wP.d.ts +2 -2
- package/dist/types/src/gen/pieces/chess/alpha/wQ.d.ts +2 -2
- package/dist/types/src/gen/pieces/chess/alpha/wR.d.ts +2 -2
- package/dist/types/src/gen/pieces/chess/cburnett/bB.d.ts +2 -2
- package/dist/types/src/gen/pieces/chess/cburnett/bB.d.ts.map +1 -1
- package/dist/types/src/gen/pieces/chess/cburnett/bK.d.ts +2 -2
- package/dist/types/src/gen/pieces/chess/cburnett/bK.d.ts.map +1 -1
- package/dist/types/src/gen/pieces/chess/cburnett/bN.d.ts +2 -2
- package/dist/types/src/gen/pieces/chess/cburnett/bN.d.ts.map +1 -1
- package/dist/types/src/gen/pieces/chess/cburnett/bP.d.ts +2 -2
- package/dist/types/src/gen/pieces/chess/cburnett/bQ.d.ts +2 -2
- package/dist/types/src/gen/pieces/chess/cburnett/bQ.d.ts.map +1 -1
- package/dist/types/src/gen/pieces/chess/cburnett/bR.d.ts +2 -2
- package/dist/types/src/gen/pieces/chess/cburnett/bR.d.ts.map +1 -1
- package/dist/types/src/gen/pieces/chess/cburnett/index.d.ts +12 -12
- package/dist/types/src/gen/pieces/chess/cburnett/wB.d.ts +2 -2
- package/dist/types/src/gen/pieces/chess/cburnett/wB.d.ts.map +1 -1
- package/dist/types/src/gen/pieces/chess/cburnett/wK.d.ts +2 -2
- package/dist/types/src/gen/pieces/chess/cburnett/wK.d.ts.map +1 -1
- package/dist/types/src/gen/pieces/chess/cburnett/wN.d.ts +2 -2
- package/dist/types/src/gen/pieces/chess/cburnett/wN.d.ts.map +1 -1
- package/dist/types/src/gen/pieces/chess/cburnett/wP.d.ts +2 -2
- package/dist/types/src/gen/pieces/chess/cburnett/wQ.d.ts +2 -2
- package/dist/types/src/gen/pieces/chess/cburnett/wQ.d.ts.map +1 -1
- package/dist/types/src/gen/pieces/chess/cburnett/wR.d.ts +2 -2
- package/dist/types/src/gen/pieces/chess/cburnett/wR.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -2
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +27 -22
- package/src/{Chessboard → components/Chessboard}/Chessboard.stories.tsx +32 -29
- package/src/{Chessboard → components/Chessboard}/Chessboard.tsx +72 -60
- package/src/components/Chessboard/chess.test.ts +19 -0
- package/src/components/Chessboard/chess.ts +325 -0
- package/src/components/Gameboard/Gameboard.tsx +139 -0
- package/src/{Gameboard → components/Gameboard}/Piece.tsx +27 -23
- package/src/{Gameboard → components/Gameboard}/Square.tsx +8 -6
- package/src/{Gameboard → components/Gameboard}/index.ts +0 -3
- package/src/{Gameboard → components/Gameboard}/types.ts +4 -2
- package/src/components/index.ts +6 -0
- package/src/gen/pieces/chess/alpha/bB.tsx +9 -6
- package/src/gen/pieces/chess/alpha/bK.tsx +7 -7
- package/src/gen/pieces/chess/alpha/bN.tsx +7 -7
- package/src/gen/pieces/chess/alpha/bP.tsx +5 -5
- package/src/gen/pieces/chess/alpha/bQ.tsx +9 -6
- package/src/gen/pieces/chess/alpha/bR.tsx +6 -6
- package/src/gen/pieces/chess/alpha/index.ts +12 -12
- package/src/gen/pieces/chess/alpha/wB.tsx +7 -7
- package/src/gen/pieces/chess/alpha/wK.tsx +7 -7
- package/src/gen/pieces/chess/alpha/wN.tsx +7 -7
- package/src/gen/pieces/chess/alpha/wP.tsx +7 -7
- package/src/gen/pieces/chess/alpha/wQ.tsx +7 -7
- package/src/gen/pieces/chess/alpha/wR.tsx +7 -7
- package/src/gen/pieces/chess/cburnett/bB.tsx +20 -9
- package/src/gen/pieces/chess/cburnett/bK.tsx +25 -15
- package/src/gen/pieces/chess/cburnett/bN.tsx +20 -13
- package/src/gen/pieces/chess/cburnett/bP.tsx +6 -6
- package/src/gen/pieces/chess/cburnett/bQ.tsx +19 -13
- package/src/gen/pieces/chess/cburnett/bR.tsx +27 -11
- package/src/gen/pieces/chess/cburnett/index.ts +12 -12
- package/src/gen/pieces/chess/cburnett/wB.tsx +19 -9
- package/src/gen/pieces/chess/cburnett/wK.tsx +19 -12
- package/src/gen/pieces/chess/cburnett/wN.tsx +16 -9
- package/src/gen/pieces/chess/cburnett/wP.tsx +7 -7
- package/src/gen/pieces/chess/cburnett/wQ.tsx +19 -9
- package/src/gen/pieces/chess/cburnett/wR.tsx +19 -9
- package/src/index.ts +1 -2
- package/dist/types/src/Chessboard/Chessboard.d.ts +0 -15
- package/dist/types/src/Chessboard/Chessboard.d.ts.map +0 -1
- package/dist/types/src/Chessboard/Chessboard.stories.d.ts +0 -16
- package/dist/types/src/Chessboard/Chessboard.stories.d.ts.map +0 -1
- package/dist/types/src/Chessboard/chess.d.ts +0 -40
- package/dist/types/src/Chessboard/chess.d.ts.map +0 -1
- package/dist/types/src/Chessboard/index.d.ts.map +0 -1
- package/dist/types/src/Gameboard/Gameboard.d.ts +0 -23
- package/dist/types/src/Gameboard/Gameboard.d.ts.map +0 -1
- package/dist/types/src/Gameboard/Piece.d.ts.map +0 -1
- package/dist/types/src/Gameboard/Square.d.ts.map +0 -1
- package/dist/types/src/Gameboard/context.d.ts +0 -10
- package/dist/types/src/Gameboard/context.d.ts.map +0 -1
- package/dist/types/src/Gameboard/index.d.ts +0 -7
- package/dist/types/src/Gameboard/index.d.ts.map +0 -1
- package/dist/types/src/Gameboard/types.d.ts.map +0 -1
- package/dist/types/src/Gameboard/util.d.ts.map +0 -1
- package/src/Chessboard/chess.ts +0 -213
- package/src/Gameboard/Gameboard.tsx +0 -103
- package/src/Gameboard/context.ts +0 -22
- /package/dist/types/src/{Chessboard → components/Chessboard}/index.d.ts +0 -0
- /package/dist/types/src/{Gameboard → components/Gameboard}/Square.d.ts +0 -0
- /package/dist/types/src/{Gameboard → components/Gameboard}/util.d.ts +0 -0
- /package/src/{Chessboard → components/Chessboard}/index.ts +0 -0
- /package/src/{Gameboard → components/Gameboard}/util.ts +0 -0
|
@@ -1,20 +1,27 @@
|
|
|
1
|
-
import * as React from
|
|
2
|
-
import type { SVGProps } from
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { SVGProps } from "react";
|
|
3
3
|
const SvgWK = (props: SVGProps<SVGSVGElement>) => (
|
|
4
|
-
<svg xmlns=
|
|
5
|
-
<g
|
|
6
|
-
|
|
4
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 45 45" {...props}>
|
|
5
|
+
<g
|
|
6
|
+
fill="none"
|
|
7
|
+
fillRule="evenodd"
|
|
8
|
+
stroke="#000"
|
|
9
|
+
strokeLinecap="round"
|
|
10
|
+
strokeLinejoin="round"
|
|
11
|
+
strokeWidth={1.5}
|
|
12
|
+
>
|
|
13
|
+
<path strokeLinejoin="miter" d="M22.5 11.63V6M20 8h5" />
|
|
7
14
|
<path
|
|
8
|
-
fill=
|
|
9
|
-
strokeLinecap=
|
|
10
|
-
strokeLinejoin=
|
|
11
|
-
d=
|
|
15
|
+
fill="#fff"
|
|
16
|
+
strokeLinecap="butt"
|
|
17
|
+
strokeLinejoin="miter"
|
|
18
|
+
d="M22.5 25s4.5-7.5 3-10.5c0 0-1-2.5-3-2.5s-3 2.5-3 2.5c-1.5 3 3 10.5 3 10.5"
|
|
12
19
|
/>
|
|
13
20
|
<path
|
|
14
|
-
fill=
|
|
15
|
-
d=
|
|
21
|
+
fill="#fff"
|
|
22
|
+
d="M11.5 37c5.5 3.5 15.5 3.5 21 0v-7s9-4.5 6-10.5c-4-6.5-13.5-3.5-16 4V27v-3.5c-3.5-7.5-13-10.5-16-4-3 6 5 10 5 10z"
|
|
16
23
|
/>
|
|
17
|
-
<path d=
|
|
24
|
+
<path d="M11.5 30c5.5-3 15.5-3 21 0m-21 3.5c5.5-3 15.5-3 21 0m-21 3.5c5.5-3 15.5-3 21 0" />
|
|
18
25
|
</g>
|
|
19
26
|
</svg>
|
|
20
27
|
);
|
|
@@ -1,16 +1,23 @@
|
|
|
1
|
-
import * as React from
|
|
2
|
-
import type { SVGProps } from
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { SVGProps } from "react";
|
|
3
3
|
const SvgWN = (props: SVGProps<SVGSVGElement>) => (
|
|
4
|
-
<svg xmlns=
|
|
5
|
-
<g
|
|
6
|
-
|
|
4
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 45 45" {...props}>
|
|
5
|
+
<g
|
|
6
|
+
fill="none"
|
|
7
|
+
fillRule="evenodd"
|
|
8
|
+
stroke="#000"
|
|
9
|
+
strokeLinecap="round"
|
|
10
|
+
strokeLinejoin="round"
|
|
11
|
+
strokeWidth={1.5}
|
|
12
|
+
>
|
|
13
|
+
<path fill="#fff" d="M22 10c10.5 1 16.5 8 16 29H15c0-9 10-6.5 8-21" />
|
|
7
14
|
<path
|
|
8
|
-
fill=
|
|
9
|
-
d=
|
|
15
|
+
fill="#fff"
|
|
16
|
+
d="M24 18c.38 2.91-5.55 7.37-8 9-3 2-2.82 4.34-5 4-1.042-.94 1.41-3.04 0-3-1 0 .19 1.23-1 2-1 0-4.003 1-4-4 0-2 6-12 6-12s1.89-1.9 2-3.5c-.73-.994-.5-2-.5-3 1-1 3 2.5 3 2.5h2s.78-1.992 2.5-3c1 0 1 3 1 3"
|
|
10
17
|
/>
|
|
11
18
|
<path
|
|
12
|
-
fill=
|
|
13
|
-
d=
|
|
19
|
+
fill="#000"
|
|
20
|
+
d="M9.5 25.5a.5.5 0 1 1-1 0 .5.5 0 1 1 1 0m5.433-9.75a.5 1.5 30 1 1-.866-.5.5 1.5 30 1 1 .866.5"
|
|
14
21
|
/>
|
|
15
22
|
</g>
|
|
16
23
|
</svg>
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import * as React from
|
|
2
|
-
import type { SVGProps } from
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { SVGProps } from "react";
|
|
3
3
|
const SvgWP = (props: SVGProps<SVGSVGElement>) => (
|
|
4
|
-
<svg xmlns=
|
|
4
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 45 45" {...props}>
|
|
5
5
|
<path
|
|
6
|
-
fill=
|
|
7
|
-
stroke=
|
|
8
|
-
strokeLinecap=
|
|
6
|
+
fill="#fff"
|
|
7
|
+
stroke="#000"
|
|
8
|
+
strokeLinecap="round"
|
|
9
9
|
strokeWidth={1.5}
|
|
10
|
-
d=
|
|
10
|
+
d="M22.5 9c-2.21 0-4 1.79-4 4 0 .89.29 1.71.78 2.38C17.33 16.5 16 18.59 16 21c0 2.03.94 3.84 2.41 5.03-3 1.06-7.41 5.55-7.41 13.47h23c0-7.92-4.41-12.41-7.41-13.47 1.47-1.19 2.41-3 2.41-5.03 0-2.41-1.33-4.5-3.28-5.62.49-.67.78-1.49.78-2.38 0-2.21-1.79-4-4-4z"
|
|
11
11
|
/>
|
|
12
12
|
</svg>
|
|
13
13
|
);
|
|
@@ -1,15 +1,25 @@
|
|
|
1
|
-
import * as React from
|
|
2
|
-
import type { SVGProps } from
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { SVGProps } from "react";
|
|
3
3
|
const SvgWQ = (props: SVGProps<SVGSVGElement>) => (
|
|
4
|
-
<svg xmlns=
|
|
5
|
-
<g
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 45 45" {...props}>
|
|
5
|
+
<g
|
|
6
|
+
fill="#fff"
|
|
7
|
+
fillRule="evenodd"
|
|
8
|
+
stroke="#000"
|
|
9
|
+
strokeLinecap="round"
|
|
10
|
+
strokeLinejoin="round"
|
|
11
|
+
strokeWidth={1.5}
|
|
12
|
+
>
|
|
13
|
+
<path d="M8 12a2 2 0 1 1-4 0 2 2 0 1 1 4 0m16.5-4.5a2 2 0 1 1-4 0 2 2 0 1 1 4 0M41 12a2 2 0 1 1-4 0 2 2 0 1 1 4 0M16 8.5a2 2 0 1 1-4 0 2 2 0 1 1 4 0M33 9a2 2 0 1 1-4 0 2 2 0 1 1 4 0" />
|
|
8
14
|
<path
|
|
9
|
-
strokeLinecap=
|
|
10
|
-
d=
|
|
15
|
+
strokeLinecap="butt"
|
|
16
|
+
d="M9 26c8.5-1.5 21-1.5 27 0l2-12-7 11V11l-5.5 13.5-3-15-3 15-5.5-14V25L7 14z"
|
|
11
17
|
/>
|
|
12
|
-
<path
|
|
18
|
+
<path
|
|
19
|
+
strokeLinecap="butt"
|
|
20
|
+
d="M9 26c0 2 1.5 2 2.5 4 1 1.5 1 1 .5 3.5-1.5 1-1.5 2.5-1.5 2.5-1.5 1.5.5 2.5.5 2.5 6.5 1 16.5 1 23 0 0 0 1.5-1 0-2.5 0 0 .5-1.5-1-2.5-.5-2.5-.5-2 .5-3.5 1-2 2.5-2 2.5-4-8.5-1.5-18.5-1.5-27 0z"
|
|
21
|
+
/>
|
|
22
|
+
<path fill="none" d="M11.5 30c3.5-1 18.5-1 22 0M12 33.5c6-1 15-1 21 0" />
|
|
13
23
|
</g>
|
|
14
24
|
</svg>
|
|
15
25
|
);
|
|
@@ -1,13 +1,23 @@
|
|
|
1
|
-
import * as React from
|
|
2
|
-
import type { SVGProps } from
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { SVGProps } from "react";
|
|
3
3
|
const SvgWR = (props: SVGProps<SVGSVGElement>) => (
|
|
4
|
-
<svg xmlns=
|
|
5
|
-
<g
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 45 45" {...props}>
|
|
5
|
+
<g
|
|
6
|
+
fill="#fff"
|
|
7
|
+
fillRule="evenodd"
|
|
8
|
+
stroke="#000"
|
|
9
|
+
strokeLinecap="round"
|
|
10
|
+
strokeLinejoin="round"
|
|
11
|
+
strokeWidth={1.5}
|
|
12
|
+
>
|
|
13
|
+
<path
|
|
14
|
+
strokeLinecap="butt"
|
|
15
|
+
d="M9 39h27v-3H9zm3-3v-4h21v4zm-1-22V9h4v2h5V9h5v2h5V9h4v5"
|
|
16
|
+
/>
|
|
17
|
+
<path d="m34 14-3 3H14l-3-3" />
|
|
18
|
+
<path strokeLinecap="butt" strokeLinejoin="miter" d="M31 17v12.5H14V17" />
|
|
19
|
+
<path d="m31 29.5 1.5 2.5h-20l1.5-2.5" />
|
|
20
|
+
<path fill="none" strokeLinejoin="miter" d="M11 14h23" />
|
|
11
21
|
</g>
|
|
12
22
|
</svg>
|
|
13
23
|
);
|
package/src/index.ts
CHANGED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import React, { type PropsWithChildren } from 'react';
|
|
2
|
-
import { type ThemedClassName } from '@dxos/react-ui';
|
|
3
|
-
import { type Player } from '../Gameboard';
|
|
4
|
-
export type ChessboardProps = ThemedClassName<PropsWithChildren<{
|
|
5
|
-
orientation?: Player;
|
|
6
|
-
showLabels?: boolean;
|
|
7
|
-
debug?: boolean;
|
|
8
|
-
rows?: number;
|
|
9
|
-
cols?: number;
|
|
10
|
-
}>>;
|
|
11
|
-
/**
|
|
12
|
-
* Chessboard layout.
|
|
13
|
-
*/
|
|
14
|
-
export declare const Chessboard: React.MemoExoticComponent<({ orientation, showLabels, debug, rows, cols, classNames }: ChessboardProps) => React.JSX.Element>;
|
|
15
|
-
//# sourceMappingURL=Chessboard.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Chessboard.d.ts","sourceRoot":"","sources":["../../../../src/Chessboard/Chessboard.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,EAAE,KAAK,iBAAiB,EAA8C,MAAM,OAAO,CAAC;AAGlG,OAAO,EAAE,KAAK,eAAe,EAAiB,MAAM,gBAAgB,CAAC;AAKrE,OAAO,EAIL,KAAK,MAAM,EAMZ,MAAM,cAAc,CAAC;AAEtB,MAAM,MAAM,eAAe,GAAG,eAAe,CAC3C,iBAAiB,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,CAAC,CACH,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,UAAU,yFACgD,eAAe,uBA0GrF,CAAC"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import '@dxos-theme';
|
|
2
|
-
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
3
|
-
import React from 'react';
|
|
4
|
-
import { type ChessboardProps } from './Chessboard';
|
|
5
|
-
type RenderProps = Pick<ChessboardProps, 'orientation' | 'showLabels' | 'debug'> & {
|
|
6
|
-
fen: string;
|
|
7
|
-
};
|
|
8
|
-
declare const DefaultStory: ({ fen, orientation: _orientation, ...props }: RenderProps) => React.JSX.Element;
|
|
9
|
-
declare const meta: Meta<typeof DefaultStory>;
|
|
10
|
-
export default meta;
|
|
11
|
-
type Story = StoryObj<typeof DefaultStory>;
|
|
12
|
-
export declare const Default: Story;
|
|
13
|
-
export declare const Promotion: Story;
|
|
14
|
-
export declare const Debug: Story;
|
|
15
|
-
export declare const Nine: Story;
|
|
16
|
-
//# sourceMappingURL=Chessboard.stories.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Chessboard.stories.d.ts","sourceRoot":"","sources":["../../../../src/Chessboard/Chessboard.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,aAAa,CAAC;AAErB,OAAO,KAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,KAAoD,MAAM,OAAO,CAAC;AAMzE,OAAO,EAAc,KAAK,eAAe,EAAE,MAAM,cAAc,CAAC;AAIhE,KAAK,WAAW,GAAG,IAAI,CAAC,eAAe,EAAE,aAAa,GAAG,YAAY,GAAG,OAAO,CAAC,GAAG;IACjF,GAAG,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,QAAA,MAAM,YAAY,GAAI,8CAA8C,WAAW,sBA+B9E,CAAC;AA2BF,QAAA,MAAM,IAAI,EAAE,IAAI,CAAC,OAAO,YAAY,CAKnC,CAAC;AAEF,eAAe,IAAI,CAAC;AAEpB,KAAK,KAAK,GAAG,QAAQ,CAAC,OAAO,YAAY,CAAC,CAAC;AAE3C,eAAO,MAAM,OAAO,EAAE,KAAU,CAAC;AAEjC,eAAO,MAAM,SAAS,EAAE,KAIvB,CAAC;AAEF,eAAO,MAAM,KAAK,EAAE,KAOnB,CAAC;AAEF,eAAO,MAAM,IAAI,EAAE,KAElB,CAAC"}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { type ReadonlySignal } from '@preact/signals-core';
|
|
2
|
-
import { Chess } from 'chess.js';
|
|
3
|
-
import { type FC, type SVGProps } from 'react';
|
|
4
|
-
import { type Move, type Location, type PieceMap, type PieceType, type GameboardModel, type Player } from '../Gameboard';
|
|
5
|
-
export type ChessPiece = 'BK' | 'BQ' | 'BR' | 'BB' | 'BN' | 'BP' | 'WK' | 'WQ' | 'WR' | 'WB' | 'WN' | 'WP';
|
|
6
|
-
export declare const ChessPieces: Record<ChessPiece, FC<SVGProps<SVGSVGElement>>>;
|
|
7
|
-
export declare const posToLocation: (pos: string) => Location;
|
|
8
|
-
export declare const locationToPos: ([row, col]: Location) => string;
|
|
9
|
-
export declare const boardStyles: {
|
|
10
|
-
black: string;
|
|
11
|
-
white: string;
|
|
12
|
-
promotion: string;
|
|
13
|
-
};
|
|
14
|
-
export declare const getSquareColor: ([row, col]: Location) => string;
|
|
15
|
-
/**
|
|
16
|
-
* Chess model.
|
|
17
|
-
*/
|
|
18
|
-
export declare class ChessModel implements GameboardModel<ChessPiece> {
|
|
19
|
-
private _game;
|
|
20
|
-
private readonly _pieces;
|
|
21
|
-
constructor(fen?: string);
|
|
22
|
-
get turn(): Player;
|
|
23
|
-
get pieces(): ReadonlySignal<PieceMap<ChessPiece>>;
|
|
24
|
-
get game(): Chess;
|
|
25
|
-
get fen(): string;
|
|
26
|
-
initialize(fen?: string): void;
|
|
27
|
-
isValidMove(move: Move): boolean;
|
|
28
|
-
canPromote(move: Move): boolean;
|
|
29
|
-
makeMove(move: Move): boolean;
|
|
30
|
-
makeRandomMove(): boolean;
|
|
31
|
-
/**
|
|
32
|
-
* Update pieces preserving identity.
|
|
33
|
-
*/
|
|
34
|
-
private _update;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Preserve the original piece objects (and IDs).
|
|
38
|
-
*/
|
|
39
|
-
export declare const mapPieces: <T extends PieceType>(before: PieceMap<T>, after: PieceMap<T>) => PieceMap<T>;
|
|
40
|
-
//# sourceMappingURL=chess.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"chess.d.ts","sourceRoot":"","sources":["../../../../src/Chessboard/chess.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,cAAc,EAAU,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAAE,KAAK,EAAe,MAAM,UAAU,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,EAAE,KAAK,QAAQ,EAAE,MAAM,OAAO,CAAC;AAI/C,OAAO,EACL,KAAK,IAAI,EACT,KAAK,QAAQ,EACb,KAAK,QAAQ,EAEb,KAAK,SAAS,EACd,KAAK,cAAc,EACnB,KAAK,MAAM,EACZ,MAAM,cAAc,CAAC;AAGtB,MAAM,MAAM,UAAU,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AAE3G,eAAO,MAAM,WAAW,EAAE,MAAM,CAAC,UAAU,EAAE,EAAE,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,CAAS,CAAC;AAElF,eAAO,MAAM,aAAa,GAAI,KAAK,MAAM,KAAG,QAI3C,CAAC;AAEF,eAAO,MAAM,aAAa,GAAI,YAAY,QAAQ,KAAG,MAEpD,CAAC;AAyBF,eAAO,MAAM,WAAW;;;;CAAkB,CAAC;AAE3C,eAAO,MAAM,cAAc,GAAI,YAAY,QAAQ,WAElD,CAAC;AAmBF;;GAEG;AACH,qBAAa,UAAW,YAAW,cAAc,CAAC,UAAU,CAAC;IAC3D,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAoC;gBAEhD,GAAG,CAAC,EAAE,MAAM;IAIxB,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,IAAI,MAAM,IAAI,cAAc,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAEjD;IAED,IAAI,IAAI,IAAI,KAAK,CAEhB;IAED,IAAI,GAAG,IAAI,MAAM,CAEhB;IAED,UAAU,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI;IAM9B,WAAW,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO;IAIhC,UAAU,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO;IAM/B,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO;IAW7B,cAAc,IAAI,OAAO;IAYzB;;OAEG;IACH,OAAO,CAAC,OAAO;CAsBhB;AAED;;GAEG;AACH,eAAO,MAAM,SAAS,GAAI,CAAC,SAAS,SAAS,EAAE,QAAQ,QAAQ,CAAC,CAAC,CAAC,EAAE,OAAO,QAAQ,CAAC,CAAC,CAAC,KAAG,QAAQ,CAAC,CAAC,CAmClG,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/Chessboard/index.ts"],"names":[],"mappings":"AAIA,cAAc,SAAS,CAAC;AAExB,cAAc,cAAc,CAAC"}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import React, { type CSSProperties, type PropsWithChildren } from 'react';
|
|
2
|
-
import { type ThemedClassName } from '@dxos/react-ui';
|
|
3
|
-
import { type GameboardModel, type Move } from './types';
|
|
4
|
-
type GameboardRootProps = PropsWithChildren<{
|
|
5
|
-
model?: GameboardModel;
|
|
6
|
-
onDrop?: (move: Move) => boolean;
|
|
7
|
-
}>;
|
|
8
|
-
type GameboardContentsProps = ThemedClassName<PropsWithChildren<{
|
|
9
|
-
style?: CSSProperties;
|
|
10
|
-
}>>;
|
|
11
|
-
export declare const Gameboard: {
|
|
12
|
-
Root: {
|
|
13
|
-
({ children, model, onDrop }: GameboardRootProps): React.JSX.Element;
|
|
14
|
-
displayName: string;
|
|
15
|
-
};
|
|
16
|
-
Content: React.ForwardRefExoticComponent<Omit<React.PropsWithChildren<{
|
|
17
|
-
style?: CSSProperties;
|
|
18
|
-
}>, "className"> & {
|
|
19
|
-
classNames?: import("@dxos/react-ui-types").ClassNameValue;
|
|
20
|
-
} & React.RefAttributes<HTMLDivElement>>;
|
|
21
|
-
};
|
|
22
|
-
export type { GameboardRootProps, GameboardContentsProps };
|
|
23
|
-
//# sourceMappingURL=Gameboard.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Gameboard.d.ts","sourceRoot":"","sources":["../../../../src/Gameboard/Gameboard.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,EAAE,KAAK,aAAa,EAAc,KAAK,iBAAiB,EAAoC,MAAM,OAAO,CAAC;AAGxH,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAItD,OAAO,EAAE,KAAK,cAAc,EAAuB,KAAK,IAAI,EAAoB,MAAM,SAAS,CAAC;AAEhG,KAAK,kBAAkB,GAAG,iBAAiB,CAAC;IAC1C,KAAK,CAAC,EAAE,cAAc,CAAC;IACvB,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC;CAClC,CAAC,CAAC;AA6DH,KAAK,sBAAsB,GAAG,eAAe,CAC3C,iBAAiB,CAAC;IAChB,KAAK,CAAC,EAAE,aAAa,CAAC;CACvB,CAAC,CACH,CAAC;AAeF,eAAO,MAAM,SAAS;;sCA3E8B,kBAAkB;;;;gBA0D1D,aAAa;;;;CAoBxB,CAAC;AAEF,YAAY,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Piece.d.ts","sourceRoot":"","sources":["../../../../src/Gameboard/Piece.tsx"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,EAA+B,KAAK,EAAE,EAAE,KAAK,QAAQ,EAAQ,MAAM,OAAO,CAAC;AAKzF,OAAO,EAAgC,KAAK,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAIpF,OAAO,EAA8C,KAAK,WAAW,EAAE,KAAK,MAAM,EAAE,MAAM,SAAS,CAAC;AACpG,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,QAAQ,CAAC;AAE5C,MAAM,MAAM,UAAU,GAAG,eAAe,CAAC;IACvC,KAAK,EAAE,WAAW,CAAC;IACnB,MAAM,EAAE,aAAa,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,EAAE,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,CAAC;CACxC,CAAC,CAAC;AAEH,eAAO,MAAM,KAAK,2FAAuE,UAAU,uBAwGjG,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Square.d.ts","sourceRoot":"","sources":["../../../../src/Gameboard/Square.tsx"],"names":[],"mappings":"AAKA,OAAO,KAA4C,MAAM,OAAO,CAAC;AAIjE,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAItD,OAAO,EAAW,KAAK,QAAQ,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,QAAQ,CAAC;AAI5C,MAAM,MAAM,WAAW,GAAG,eAAe,CAAC;IACxC,QAAQ,EAAE,QAAQ,CAAC;IACnB,MAAM,EAAE,aAAa,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC,CAAC;AAEH,eAAO,MAAM,MAAM,sEAAkD,WAAW,uBA+C9E,CAAC"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { type PieceRecord, type GameboardModel, type Move } from './types';
|
|
2
|
-
export type GameboardContextType = {
|
|
3
|
-
model?: GameboardModel;
|
|
4
|
-
dragging?: boolean;
|
|
5
|
-
promoting?: PieceRecord;
|
|
6
|
-
onPromotion: (move: Move) => void;
|
|
7
|
-
};
|
|
8
|
-
export declare const GameboardContext: import("react").Context<GameboardContextType | undefined>;
|
|
9
|
-
export declare const useBoardContext: () => GameboardContextType;
|
|
10
|
-
//# sourceMappingURL=context.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../../src/Gameboard/context.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,KAAK,WAAW,EAAE,KAAK,cAAc,EAAE,KAAK,IAAI,EAAE,MAAM,SAAS,CAAC;AAE3E,MAAM,MAAM,oBAAoB,GAAG;IACjC,KAAK,CAAC,EAAE,cAAc,CAAC;IACvB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,WAAW,CAAC;IACxB,WAAW,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAC;CACnC,CAAC;AAEF,eAAO,MAAM,gBAAgB,2DAA6D,CAAC;AAE3F,eAAO,MAAM,eAAe,4BAE3B,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/Gameboard/index.ts"],"names":[],"mappings":"AAIA,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AAEvB,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/Gameboard/types.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE3D,MAAM,MAAM,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC;AAEvC,MAAM,MAAM,QAAQ,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAExC,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC;AAE/B,MAAM,MAAM,WAAW,CAAC,CAAC,SAAS,SAAS,GAAG,SAAS,IAAI;IACzD,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,CAAC,CAAC;IACR,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,QAAQ,CAAC;CACpB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,QAAQ,CAAC,CAAC,SAAS,SAAS,GAAG,SAAS,IAAI,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;AAEvF,MAAM,MAAM,IAAI,GAAG;IACjB,IAAI,EAAE,QAAQ,CAAC;IACf,EAAE,EAAE,QAAQ,CAAC;IACb,KAAK,EAAE,SAAS,CAAC;IACjB,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB,CAAC;AAEF,eAAO,MAAM,gBAAgB,GAAI,UAAU,QAAQ,KAAG,MAA4B,CAAC;AACnF,eAAO,MAAM,gBAAgB,GAAI,KAAK,MAAM,KAAG,QAAkD,CAAC;AAGlG,eAAO,MAAM,OAAO,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,WAMtB,CAAC;AAG7B,eAAO,MAAM,UAAU,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,QACwC,CAAC;AAE9F,eAAO,MAAM,eAAe,GAAI,IAAI,QAAQ,EAAE,IAAI,QAAQ,KAAG,OAA6C,CAAC;AAE3G;;GAEG;AACH,MAAM,WAAW,cAAc,CAAC,CAAC,SAAS,SAAS,GAAG,SAAS;IAC7D,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,cAAc,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;IACpC,WAAW,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC;IACrC,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC;CACtC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../../src/Gameboard/util.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,aAAa,GAAG,IAAI,CAAC,OAAO,EAAE,KAAK,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,CAAC,CAAC;AAE/E,eAAO,MAAM,iBAAiB,GAAI,WAAW,WAAW,EAAE,SAAS,WAAW,KAAG,aAShF,CAAC"}
|
package/src/Chessboard/chess.ts
DELETED
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2025 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { type ReadonlySignal, signal } from '@preact/signals-core';
|
|
6
|
-
import { Chess, validateFen } from 'chess.js';
|
|
7
|
-
import { type FC, type SVGProps } from 'react';
|
|
8
|
-
|
|
9
|
-
import { log } from '@dxos/log';
|
|
10
|
-
|
|
11
|
-
import {
|
|
12
|
-
type Move,
|
|
13
|
-
type Location,
|
|
14
|
-
type PieceMap,
|
|
15
|
-
locationToString,
|
|
16
|
-
type PieceType,
|
|
17
|
-
type GameboardModel,
|
|
18
|
-
type Player,
|
|
19
|
-
} from '../Gameboard';
|
|
20
|
-
import * as Alpha from '../gen/pieces/chess/alpha';
|
|
21
|
-
|
|
22
|
-
export type ChessPiece = 'BK' | 'BQ' | 'BR' | 'BB' | 'BN' | 'BP' | 'WK' | 'WQ' | 'WR' | 'WB' | 'WN' | 'WP';
|
|
23
|
-
|
|
24
|
-
export const ChessPieces: Record<ChessPiece, FC<SVGProps<SVGSVGElement>>> = Alpha;
|
|
25
|
-
|
|
26
|
-
export const posToLocation = (pos: string): Location => {
|
|
27
|
-
const col = pos.charCodeAt(0) - 'a'.charCodeAt(0);
|
|
28
|
-
const row = parseInt(pos[1]) - 1;
|
|
29
|
-
return [row, col];
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export const locationToPos = ([row, col]: Location): string => {
|
|
33
|
-
return String.fromCharCode(col + 'a'.charCodeAt(0)) + (row + 1);
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
const styles = {
|
|
37
|
-
neutral: {
|
|
38
|
-
black: 'bg-neutral-50',
|
|
39
|
-
white: 'bg-neutral-200',
|
|
40
|
-
promotion: 'bg-neutral-200 hover:bg-neutral-300 opacity-70 hover:opacity-100',
|
|
41
|
-
},
|
|
42
|
-
original: {
|
|
43
|
-
black: 'bg-[#6C95B9]',
|
|
44
|
-
white: 'bg-[#CCD3DB]',
|
|
45
|
-
promotion: 'duration-500 bg-[#CCD3DB] opacity-70 hover:opacity-100',
|
|
46
|
-
},
|
|
47
|
-
blue: {
|
|
48
|
-
black: 'bg-[#608BC1]',
|
|
49
|
-
white: 'bg-[#CBDCEB]',
|
|
50
|
-
promotion: 'duration-500 bg-[#CBDCEB] opacity-70 hover:opacity-100',
|
|
51
|
-
},
|
|
52
|
-
green: {
|
|
53
|
-
black: 'bg-[#8EB486]',
|
|
54
|
-
white: 'bg-[#FDF7F4]',
|
|
55
|
-
promotion: 'duration-500 bg-[#FDF7F4] opacity-70 hover:opacity-100',
|
|
56
|
-
},
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
export const boardStyles = styles.original;
|
|
60
|
-
|
|
61
|
-
export const getSquareColor = ([row, col]: Location) => {
|
|
62
|
-
return (col + row) % 2 === 0 ? boardStyles.black : boardStyles.white;
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Attempt move.
|
|
67
|
-
*/
|
|
68
|
-
const makeMove = (game: Chess, move: Move): Chess | null => {
|
|
69
|
-
const from = locationToPos(move.from);
|
|
70
|
-
const to = locationToPos(move.to);
|
|
71
|
-
try {
|
|
72
|
-
log('makeMove', { move });
|
|
73
|
-
const promotion = move.promotion ? move.promotion[1].toLowerCase() : 'q';
|
|
74
|
-
game.move({ from, to, promotion }, { strict: false });
|
|
75
|
-
return game;
|
|
76
|
-
} catch (err) {
|
|
77
|
-
// Ignore.
|
|
78
|
-
return null;
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Chess model.
|
|
84
|
-
*/
|
|
85
|
-
export class ChessModel implements GameboardModel<ChessPiece> {
|
|
86
|
-
private _game!: Chess;
|
|
87
|
-
private readonly _pieces = signal<PieceMap<ChessPiece>>({});
|
|
88
|
-
|
|
89
|
-
constructor(fen?: string) {
|
|
90
|
-
this.initialize(fen);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
get turn(): Player {
|
|
94
|
-
return this._game.turn() === 'w' ? 'white' : 'black';
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
get pieces(): ReadonlySignal<PieceMap<ChessPiece>> {
|
|
98
|
-
return this._pieces;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
get game(): Chess {
|
|
102
|
-
return this._game;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
get fen(): string {
|
|
106
|
-
return this._game.fen();
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
initialize(fen?: string): void {
|
|
110
|
-
this._pieces.value = {};
|
|
111
|
-
this._game = new Chess(fen ? (validateFen(fen).ok ? fen : undefined) : undefined);
|
|
112
|
-
this._update();
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
isValidMove(move: Move): boolean {
|
|
116
|
-
return makeMove(new Chess(this._game.fen()), move) !== null;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
canPromote(move: Move): boolean {
|
|
120
|
-
const isPawnMove = move.piece === 'BP' || move.piece === 'WP';
|
|
121
|
-
const isToLastRank = move.to[0] === 0 || move.to[0] === 7;
|
|
122
|
-
return isPawnMove && isToLastRank;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
makeMove(move: Move): boolean {
|
|
126
|
-
const game = makeMove(this._game, move);
|
|
127
|
-
if (!game) {
|
|
128
|
-
return false;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
this._game = game;
|
|
132
|
-
this._update();
|
|
133
|
-
return true;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
makeRandomMove(): boolean {
|
|
137
|
-
const moves = this._game.moves();
|
|
138
|
-
if (!moves.length) {
|
|
139
|
-
return false;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
const move = moves[Math.floor(Math.random() * moves.length)];
|
|
143
|
-
this._game.move(move);
|
|
144
|
-
this._update();
|
|
145
|
-
return true;
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Update pieces preserving identity.
|
|
150
|
-
*/
|
|
151
|
-
private _update(): void {
|
|
152
|
-
const pieces: PieceMap<ChessPiece> = {};
|
|
153
|
-
this._game.board().flatMap((row) =>
|
|
154
|
-
row.forEach((record) => {
|
|
155
|
-
if (!record) {
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
const { square, type, color } = record;
|
|
160
|
-
const pieceType = `${color.toUpperCase()}${type.toUpperCase()}` as ChessPiece;
|
|
161
|
-
const location = posToLocation(square);
|
|
162
|
-
pieces[locationToString(location)] = {
|
|
163
|
-
id: `${square}-${pieceType}`,
|
|
164
|
-
type: pieceType,
|
|
165
|
-
side: color === 'w' ? 'white' : 'black',
|
|
166
|
-
location,
|
|
167
|
-
};
|
|
168
|
-
}),
|
|
169
|
-
);
|
|
170
|
-
|
|
171
|
-
this._pieces.value = mapPieces(this._pieces.value, pieces);
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* Preserve the original piece objects (and IDs).
|
|
177
|
-
*/
|
|
178
|
-
export const mapPieces = <T extends PieceType>(before: PieceMap<T>, after: PieceMap<T>): PieceMap<T> => {
|
|
179
|
-
const difference: { added: PieceMap; removed: PieceMap } = {
|
|
180
|
-
removed: {},
|
|
181
|
-
added: {},
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
(Object.keys(before) as Array<keyof typeof before>).forEach((square) => {
|
|
185
|
-
if (after[square]?.type !== before[square]?.type) {
|
|
186
|
-
difference.removed[square] = before[square];
|
|
187
|
-
}
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
(Object.keys(after) as Array<keyof typeof after>).forEach((square) => {
|
|
191
|
-
if (before[square]?.type !== after[square]?.type) {
|
|
192
|
-
difference.added[square] = after[square];
|
|
193
|
-
} else {
|
|
194
|
-
after[square] = before[square];
|
|
195
|
-
}
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
for (const piece of Object.values(difference.added)) {
|
|
199
|
-
const previous = Object.values(difference.removed).find((p) => p.type === piece.type);
|
|
200
|
-
if (previous) {
|
|
201
|
-
piece.id = previous.id;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
log('delta', {
|
|
206
|
-
before: Object.keys(before).length,
|
|
207
|
-
after: Object.keys(after).length,
|
|
208
|
-
removed: Object.keys(difference.removed).length,
|
|
209
|
-
added: Object.keys(difference.added).length,
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
return after;
|
|
213
|
-
};
|