chess4js 1.0.0-beta.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/LICENSE +201 -0
- package/README.md +341 -0
- package/chess4js.d.mts +357 -0
- package/chess4js.mjs +11605 -0
- package/chess4js.mjs.map +1 -0
- package/kotlin-kotlin-stdlib.mjs +7828 -0
- package/kotlin-kotlin-stdlib.mjs.map +1 -0
- package/kotlin_org_jetbrains_kotlin_kotlin_dom_api_compat.mjs +4 -0
- package/kotlin_org_jetbrains_kotlin_kotlin_dom_api_compat.mjs.map +1 -0
- package/package.json +21 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
[](https://www.npmjs.com/package/ll-grid-vue-3)
|
|
2
|
+

|
|
3
|
+
|
|
4
|
+
# Chess4js
|
|
5
|
+
|
|
6
|
+
# OVERVIEW
|
|
7
|
+
|
|
8
|
+
**Chess4js** is a JavaScript transpilation of **Chess4kt**, my Kotlin Multiplatform chess library.
|
|
9
|
+
|
|
10
|
+
This library offers nearly all the features of its Kotlin counterpart. It is currently in **beta**; while fully
|
|
11
|
+
functional, initialization performance is still being optimized.
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
# Classes
|
|
16
|
+
|
|
17
|
+
### Square
|
|
18
|
+
|
|
19
|
+
`Square` is a non-instantiable class representing a square on the board. It contains two main properties:
|
|
20
|
+
|
|
21
|
+
| Property | Type | Description |
|
|
22
|
+
|----------|--------|--------------------------------------------------------|
|
|
23
|
+
| ordinal | number | Internal numerical representation used by the library. |
|
|
24
|
+
| name | string | The algebraic name of the square (e.g., "A1"). |
|
|
25
|
+
|
|
26
|
+
The library provides predefined instances for every square (A1, B1, ..., H8). You can import them directly:
|
|
27
|
+
|
|
28
|
+
```js
|
|
29
|
+
import { A1, G4, D6 } from "chess4js";
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Piece
|
|
33
|
+
|
|
34
|
+
`Piece` is a non-instantiable class representing a chess piece.
|
|
35
|
+
|
|
36
|
+
| Property | Type | Description |
|
|
37
|
+
|----------|--------|--------------------------------------------------------|
|
|
38
|
+
| ordinal | number | Internal numerical representation used by the library. |
|
|
39
|
+
| name | string | The name of the piece. |
|
|
40
|
+
|
|
41
|
+
Predefined instances are available for all pieces:
|
|
42
|
+
|
|
43
|
+
- White: WP, WN, WB, WR , WQ, WK.
|
|
44
|
+
- Black: BP, BN, BB, BR, BQ, BK.
|
|
45
|
+
|
|
46
|
+
You can import them directly:
|
|
47
|
+
|
|
48
|
+
```js
|
|
49
|
+
import {WP, BK, WQ, BN} from "chess4js"
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Side
|
|
53
|
+
|
|
54
|
+
`Side` is a non-instantiable class representing the players. It has a `name` property (string). Only two instances
|
|
55
|
+
exist: `WHITE` and `BLACK`. You can import them directly:
|
|
56
|
+
|
|
57
|
+
```js
|
|
58
|
+
import { WHITE, BLACK } from "chess4js"
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Bitboard
|
|
62
|
+
|
|
63
|
+
A non-directly instantiable class representing a 64-bit bitboard. Instances are immutable.
|
|
64
|
+
|
|
65
|
+
### Methods
|
|
66
|
+
|
|
67
|
+
| Method | Arguments | Return Type | Description |
|
|
68
|
+
|---------------|-----------------|-------------|-------------------------------------------------------------------------|
|
|
69
|
+
| peekLastBit | None | Bitboard | Returns a bitboard containing only the Least Significant Bit (LSB). |
|
|
70
|
+
| peekFirstBit | None | Bitboard | Returns a bitboard containing only the Most Significant Bit (MSB). |
|
|
71
|
+
| trailingZeros | None | number | Returns the number of zero bits following the LSB. |
|
|
72
|
+
| leadingZeros | None | number | Returns the number of zero bits preceding the MSB. |
|
|
73
|
+
| and | other: Bitboard | Bitboard | Performs a bitwise AND operation. |
|
|
74
|
+
| or | other: Bitboard | Bitboard | Performs a bitwise OR operation. |
|
|
75
|
+
| xor | other: Bitboard | Bitboard | Performs a bitwise XOR operation. |
|
|
76
|
+
| inv | None | Bitboard | Performs a bitwise NOT operation (inverts all bits). |
|
|
77
|
+
| shl | i: number | Bitboard | Returns a bitboard with bits shifted left by i positions. |
|
|
78
|
+
| ushr | i: number | Bitboard | Returns a bitboard with bits shifted right (unsigned) by `i` positions. |
|
|
79
|
+
| toString | none | string | Returns a formatted string representation. |
|
|
80
|
+
|
|
81
|
+
Instances of this class can be obtained from `Position` instances.
|
|
82
|
+
|
|
83
|
+
## Move
|
|
84
|
+
|
|
85
|
+
A non directly instantiable class that represents a move made on the board.
|
|
86
|
+
|
|
87
|
+
### Properties
|
|
88
|
+
|
|
89
|
+
| Property | Type | Description |
|
|
90
|
+
|----------------|--------|-------------------------------------------------------------------------|
|
|
91
|
+
| origin | number | The zero-based index (0-63) of the move's origin square. |
|
|
92
|
+
| target | number | The zero-based index (0-63) of the move's target square. |
|
|
93
|
+
| promotionPiece | number | The ordinal value of the promotion piece, or -1 if no promotion occurs. |
|
|
94
|
+
|
|
95
|
+
### Methods
|
|
96
|
+
|
|
97
|
+
| Method | Arguments | Return Type | Description |
|
|
98
|
+
|----------|-----------|-------------|-----------------------------------------|
|
|
99
|
+
| toString | None | string | Returns the UCI notation for this move. |
|
|
100
|
+
|
|
101
|
+
### Factories
|
|
102
|
+
|
|
103
|
+
| Function | Arguments | Return Type | Description |
|
|
104
|
+
|----------|--------------|-------------|-----------------------------------------------------------------------|
|
|
105
|
+
| moveOf | move: String | Move | Creates a `Move` object from its UCI notation string (e.g., "e7e8q"). |
|
|
106
|
+
|
|
107
|
+
### Example
|
|
108
|
+
|
|
109
|
+
```js
|
|
110
|
+
import { moveOf } from "chess4js"
|
|
111
|
+
|
|
112
|
+
const myMove = moveOf("e2e4");
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Position
|
|
116
|
+
|
|
117
|
+
Represents a specific board state. Instances of this class are immutable. Modifying properties directly will lead to
|
|
118
|
+
inconsistent behavior. Use factory methods to generate new positions.
|
|
119
|
+
|
|
120
|
+
```js
|
|
121
|
+
import { startpos, positionOf } from "chess4js"
|
|
122
|
+
|
|
123
|
+
const initialPosition = startpos();
|
|
124
|
+
const somePosition = positionOf("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1");
|
|
125
|
+
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### Properties
|
|
129
|
+
|
|
130
|
+
| Property | Type | Description |
|
|
131
|
+
|----------------------|------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
132
|
+
| bitboards | ReadonlyArray\<Bitboard\> | The index in the array is equal to the ordinal value minus one of the corresponding piece (e.g., Black Knight distribution is at index `BN.ordinal - 1`). Each Bitboard has 64 bits, where each bit represents a square in the board, following the Square ordinal order (A1 is bit 0, B1 is bit 1, up to H8 which is bit 63). A bit set to 1 indicates the presence of the piece corresponding to the array index, and 0 indicates absence. |
|
|
133
|
+
| whiteMove | boolean | True if it is White's turn to move. False if it is Black's turn. |
|
|
134
|
+
| enPassant | number | The square index (0-63) where a pawn can be captured en passant. Returns -1 if no en passant capture is possible. |
|
|
135
|
+
| whiteCastleKingside | boolean | True if White can castle kingside (short castling). False otherwise. |
|
|
136
|
+
| whiteCastleQueenside | boolean | True if White can castle queenside (long castling). False otherwise. |
|
|
137
|
+
| blackCastleKingside | boolean | True if Black can castle kingside (short castling). False otherwise. |
|
|
138
|
+
| blackCastleQueenside | boolean | True if Black can castle queenside (long castling). False otherwise. |
|
|
139
|
+
| movesCounter | number | The full move number in the game (starts at 1 and is incremented after Black's move). |
|
|
140
|
+
| halfMovesCounter | number | The number of half-moves since the last pawn move or capture. This is used for the 50-move rule. |
|
|
141
|
+
| check | boolean | True if the current side to move is in check. False otherwise. |
|
|
142
|
+
| checkmate | boolean | True if the position is a checkmate (the current side is in check and has no legal moves). False otherwise. |
|
|
143
|
+
| stalemate | boolean | True if the position is a stalemate (the current side is not in check but has no legal moves). False otherwise. |
|
|
144
|
+
| lackOfMaterial | boolean | True if the position is a draw due to insufficient mating material (e.g., King vs. King). False otherwise. |
|
|
145
|
+
| fiftyMoves | boolean | True if the position has reached or exceeded 50 half-moves without a pawn move or capture. |
|
|
146
|
+
| zobrist | Bitboard | The Zobrist hash key of the position. This is used for efficient position lookup and repetition detection. |
|
|
147
|
+
| squares | Int32Array | A 64-element array where the index corresponds to the square order defined in Square (A1=0, H8=63). The value of each element is the ordinal of the Piece occupying that square (0 for EMPTY, 1 for WP, and so on). |
|
|
148
|
+
| fen | string | The FEN (Forsyth-Edwards Notation) string representation of the position. |
|
|
149
|
+
| children | ReadonlyArray\<Tuple\<Position, Move\>\> | A list of tuples, where each tuple represents a legal move from this position and the resulting new position (Tuple<Position, Move>). This list effectively defines the legal branches of the game tree from the current position. |
|
|
150
|
+
| draw | boolean | True if the position is a forced draw. This is true if the position results in a stalemate or lackOfMaterial. False otherwise. |
|
|
151
|
+
| enPassantSquare | Nullable\<Square\> | The square exposed to an en passant capture, if one exists. Returns null if no en passant capture is possible in the current position. |
|
|
152
|
+
| gameOver | boolean | True if the game state is concluded (terminal position), either due to a forced draw or checkmate. False otherwise. |
|
|
153
|
+
| sideToMove | Side | The side (WHITE or BLACK) whose turn it is to move. |
|
|
154
|
+
|
|
155
|
+
### Methods
|
|
156
|
+
|
|
157
|
+
| Method | Arguments | Return Type | Description |
|
|
158
|
+
|----------------------|----------------------------------------|-------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
159
|
+
| whiteLacksOfMaterial | None | boolean | Determines if White has insufficient material to win the game. Returns true if the current pieces for White cannot potentially lead to a checkmate. |
|
|
160
|
+
| blackLacksOfMaterial | None | boolean | Determines if Black has insufficient material to win the game. Returns true if the current pieces for Black cannot potentially lead to a checkmate. |
|
|
161
|
+
| pieceAt | square: Square | Piece | Retrieves the piece object that occupies the given square. |
|
|
162
|
+
| isLegal | move: Move | boolean | Returns true if the evaluated Move is legal in the current position, and false otherwise. |
|
|
163
|
+
| move | move: Move | Position | Retrieves the new Position that results from executing the provided legal Move. Throws a MoveException if the provided move is not legal in the current position. |
|
|
164
|
+
| moveFromString | move: String, notation: Notation = UCI | Position | Retrieves the new Position that results from executing the move specified in the given notation. Throws a MoveException if the move is not legal. If no notation is provided, UCI notation is assumed. |
|
|
165
|
+
| toString | None | string | retrieves a nice string representation |
|
|
166
|
+
|
|
167
|
+
### Factories
|
|
168
|
+
|
|
169
|
+
| Function | Arguments | Return Type | Description |
|
|
170
|
+
|------------|-------------|-------------|-----------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
171
|
+
| startpos | None | Position | Returns the standard starting `Position` (the startpos FEN). |
|
|
172
|
+
| positionOf | fen: String | Position | Factory function to create a `Position` object from a FEN string. Throws an exception if the FEN string is invalid or leads to an illegal position. |
|
|
173
|
+
|
|
174
|
+
## Tuple
|
|
175
|
+
|
|
176
|
+
A utility class designed to group a `Position` and a `Move` together.
|
|
177
|
+
|
|
178
|
+
### Properties
|
|
179
|
+
|
|
180
|
+
| Property | Type | Description |
|
|
181
|
+
|----------|----------|--------------|
|
|
182
|
+
| position | Position | The position |
|
|
183
|
+
| move | Move | The move |
|
|
184
|
+
|
|
185
|
+
## Notation
|
|
186
|
+
|
|
187
|
+
This non-instantiable class represents the types of move notation supported by this library.
|
|
188
|
+
The library provides two predefined instances: `UCI` (long algebraic notation used in the UCI protocol) and `SAN` (standard
|
|
189
|
+
algebraic notation).
|
|
190
|
+
|
|
191
|
+
### Properties
|
|
192
|
+
|
|
193
|
+
| Property | Type | Description |
|
|
194
|
+
|----------|--------|-------------------|
|
|
195
|
+
| name | String | The notation name |
|
|
196
|
+
|
|
197
|
+
## Game and Node
|
|
198
|
+
|
|
199
|
+
The `Game` class represents a match or an analysis game.
|
|
200
|
+
It is basically a tree of `Node` objects with some other properties like tags.
|
|
201
|
+
If an instance is used to represent a documented match then its structure becomes like a linked list.
|
|
202
|
+
|
|
203
|
+
```mermaid
|
|
204
|
+
|
|
205
|
+
---
|
|
206
|
+
config:
|
|
207
|
+
theme: neo-dark
|
|
208
|
+
layout: dagre
|
|
209
|
+
look: classic
|
|
210
|
+
---
|
|
211
|
+
flowchart LR
|
|
212
|
+
subgraph subGraph0["Game Tree"]
|
|
213
|
+
B["MoveNode
|
|
214
|
+
(1. e4 - First move)"]
|
|
215
|
+
A["Node
|
|
216
|
+
(Start position of the game)"]
|
|
217
|
+
C@{ label: "Node\n (1... c5 - Black's response)" }
|
|
218
|
+
D["Node
|
|
219
|
+
(2. Nf3 - Next main move)"]
|
|
220
|
+
E["Node
|
|
221
|
+
(2. d4 - Alternative move by White)"]
|
|
222
|
+
F@{ label: "Node\n (2... cxd4 - Black's response in variation)" }
|
|
223
|
+
end
|
|
224
|
+
A -- children 0: Main line --> B
|
|
225
|
+
B -- children 0: Main line --> C
|
|
226
|
+
C -- children 0: Main line --> D
|
|
227
|
+
C -- children 1: Variation --> E
|
|
228
|
+
E -- children 0: Main line of the variation --> F
|
|
229
|
+
|
|
230
|
+
C@{ shape: rect}
|
|
231
|
+
F@{ shape: rect}
|
|
232
|
+
style B fill: #424242, stroke: #333
|
|
233
|
+
style A fill: #424242, stroke: #424242
|
|
234
|
+
style C fill: #424242, stroke: #333
|
|
235
|
+
style D fill: #424242, stroke: #333
|
|
236
|
+
style E fill: #424242, stroke: #333
|
|
237
|
+
style F fill: #424242, stroke: #333
|
|
238
|
+
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
### Properties
|
|
242
|
+
|
|
243
|
+
For the `Game` class:
|
|
244
|
+
|
|
245
|
+
| Property | Type | Description |
|
|
246
|
+
|-------------------------|---------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
247
|
+
| root | Node | The root node of the game tree. The setter is protected if the game is immutable. |
|
|
248
|
+
| ecoInfo | Nullable\<EcoInfo\> | Stores the current ECO (Encyclopedia of Chess Openings) information for the main line. Setting this property will be ignored if the game is immutable (i.e., MATCH and result is set). |
|
|
249
|
+
| id | Nullable\<any\> | A developer-provided unique identifier for serialization or tracking purposes (e.g., UUID or String). |
|
|
250
|
+
| result | Nullable\<string\> | The final result of the game. Setting this property will update the "Result" tag in tags and set the game as immutable if MATCH is used. The values can only be set to WHITE_WIN, BLACK_WIN or DRAW. |
|
|
251
|
+
| fiftyMoves | boolean | Indicates whether the 50-move half-move limit has been reached (non-terminal). |
|
|
252
|
+
| finalComment | Nullable\<string\> | An optional comment placed immediately after the game's result tag in PGN. |
|
|
253
|
+
| fiftyMovesRuleMode | string | Determines how the fifty-move rule is enforced for this game instance. The values can only be set to IGNORE, STRICT or AWARE. |
|
|
254
|
+
| finalEndLineComment | Nullable\<string\> | An optional end-of-line comment placed immediately after the game's result tag in PGN. |
|
|
255
|
+
| fiveRepetitions | boolean | Indicates whether a position has been repeated five times, leading to an automatic draw according to FIDE rules (terminal). |
|
|
256
|
+
| seventyFiveMoves | boolean | Indicates whether the 75-move half-move limit has been reached, leading to an automatic draw (terminal). |
|
|
257
|
+
| threeRepetitionsMode | string | Determines how the three-fold repetition rule is enforced for this game instance. The values can only be set to IGNORE, STRICT or AWARE. |
|
|
258
|
+
| threeRepetitionsWarning | boolean | Indicates that a three-fold repetition draw can be claimed, as the repetition is impending (e.g., the current move will complete the third repetition). |
|
|
259
|
+
| tags | any | A read-only object with keys as PGN tags names in lowercase (e.g., Event, Site, Date, Round, White, Black, Result). and values as PGN tags values |
|
|
260
|
+
|
|
261
|
+
For the `Node` class:
|
|
262
|
+
|
|
263
|
+
| Property | Type | Description |
|
|
264
|
+
|-------------------|-------------------------------------|--------------------------------------------------------------------------------------------------------------|
|
|
265
|
+
| position | Position | The position of the node, which is the result after executing the move. |
|
|
266
|
+
| move | Nullable\<Move\> | The move of the node. It is null when it is the root node, which only has the starting position of the game. |
|
|
267
|
+
| children | ReadonlyArray\<Node\> | The children of the node. The first child corresponds to the main line. The rest are variations (RAVs). |
|
|
268
|
+
| initialComment | Nullable\<string\> | The comment that precedes the move number in PGN (e.g., "{Comment} 1. e4"). |
|
|
269
|
+
| comment | Nullable\<string\> | The regular comment that follows the move and any suffix annotations (e.g., 1. e4 {Comment}). |
|
|
270
|
+
| endLineComment | Nullable\<string\> | The end-of-line comment for the node, which follows a semicolon ; and goes until the end of the line. |
|
|
271
|
+
| suffixAnnotations | Nullable\<ReadonlyArray\<number\>\> | The list of suffix annotations (NAGs) for the node. |
|
|
272
|
+
| parent | Nullable\<Node\> | The parent node. It can only be null when it is the root node, which evidently cannot have a parent. |
|
|
273
|
+
|
|
274
|
+
### Methods
|
|
275
|
+
|
|
276
|
+
For the class `Game`
|
|
277
|
+
|
|
278
|
+
| Method | Arguments | Return type | Description |
|
|
279
|
+
|---------------------|------------------------------------|------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
280
|
+
| setTag | name: String, value: String | undefined | Sets a tag pair (name and value). |
|
|
281
|
+
| getTag | name: String | Nullable<String> | Retrieves the tag's value. |
|
|
282
|
+
| toString | None | String | Returns the game in pgn format. |
|
|
283
|
+
| toAnalysis | idSupplier?: () => Nullable\<any\> | Game | Creates a deep copy of this game, converting its mode to ANALYSIS and setting both repetition rules to AWARE. This makes the new instance fully mutable for analysis. |
|
|
284
|
+
| deleteFromExclusive | node: Node | Node | Deletes all moves (the main line continuation and any variations) that follow the provided node. The node provided remains in the game. |
|
|
285
|
+
| deleteFromInclusive | node: Node | Node | Deletes all moves (the main line continuation and any variations) that follow the provided node. The move represented by the node is effectively removed from the game. |
|
|
286
|
+
| deleteBefore | node: Node | Node | Deletes all moves that preceded the provided node in the main line. The node (and its position) becomes the new effective start of the game, creating a new root Node. |
|
|
287
|
+
|
|
288
|
+
For the class `Node`
|
|
289
|
+
|
|
290
|
+
| Method | Arguments | Return type | Description |
|
|
291
|
+
|-------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
292
|
+
| appendMove | move: string, initialComment?: Nullable\<string\>, comment?: Nullable\<string\>, endLineComment?: Nullable\<string\>, suffixAnnotations?: Nullable\<ReadonlyArray\<number\>\>, notation?: Notation | Node | Appends a move and returns the added node. If the node already has a child, the added move will be a variation (RAV). Returns the new node if the move is legal, or the current node if the move is illegal. |
|
|
293
|
+
| promoteChild | index: number | boolean | Promotes the child at the given index to the primary variation (children[0]). |
|
|
294
|
+
| promoteNode | None | boolean | Promotes this node to the main line. |
|
|
295
|
+
| removeChild | node: Node | boolean | Removes the specified child node (variation) from the current node's list of children. |
|
|
296
|
+
| hasChildren | None | boolean | Checks if the node has children. |
|
|
297
|
+
| belongsToMainLine | None | boolean | Indicates whether this node belongs to the main line (i.e., it is the first child of all its ancestors). |
|
|
298
|
+
| copy | parent: Nullable\<Node\> | Node | Creates a deep copy of this node and its entire subtree, assigning the specified parent to the new copy. This process is recursive; copying the root node copies the entire game tree. |
|
|
299
|
+
|
|
300
|
+
### Factories and PGN parsing
|
|
301
|
+
|
|
302
|
+
| Function | Arguments | Return type | Description |
|
|
303
|
+
|--------------|-------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
304
|
+
| strictMatch | idSupplier?: () => Nullable\<any\> | Game | Creates a new Game instance configured for strict competitive match play. Uses MATCH with strict enforcement for the three-fold repetition and 50-move rules. |
|
|
305
|
+
| analysisGame | idSupplier?: () => Nullable\<any\> | Game | Creates a new Game instance configured for analysis. Uses ANALYSIS with AWARE, making the game fully mutable. |
|
|
306
|
+
| customGame | gameMode: string, threeRepetitionsMode: string, fiftyMovesRuleMode: string, initialFen?: Nullable\<string\>, idSupplier?: () => Nullable\<any\> | Game | Creates a new Game instance with fully customizable parameters. Allows setting the game mode, rule enforcement, initial FEN, and PGN tags. |
|
|
307
|
+
| parseGames | pgnInput: string, idSupplier?: () => Nullable\<any\> | ReadonlyArray\<Game\> | Parses a string containing one or more games in Portable Game Notation (PGN) format. Games are returned in ANALYSIS mode, making them mutable for subsequent use. |
|
|
308
|
+
|
|
309
|
+
### Example
|
|
310
|
+
|
|
311
|
+
```js
|
|
312
|
+
import { strictMatch } from "chess4js";
|
|
313
|
+
|
|
314
|
+
const myGame = strictMatch(() => "someId");
|
|
315
|
+
myGame.setTag("white", "foo")
|
|
316
|
+
myGame.setTag("black", "bar")
|
|
317
|
+
myGame.setTag("event", "foobared event")
|
|
318
|
+
myGame.setTag("site", "foobared place")
|
|
319
|
+
myGame.setTag("date", "1999.06.10")
|
|
320
|
+
|
|
321
|
+
myGame.root.appendMove("e4")
|
|
322
|
+
.appendMove("e5")
|
|
323
|
+
.appendMove("Bc4")
|
|
324
|
+
.appendMove("Nc6")
|
|
325
|
+
.appendMove("Qh5")
|
|
326
|
+
.appendMove("Nf6")
|
|
327
|
+
.appendMove("Qxf7#")
|
|
328
|
+
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
## EcoInfo
|
|
332
|
+
|
|
333
|
+
A non-instantiable class that provides basic information about ECO classification.
|
|
334
|
+
|
|
335
|
+
### Properties
|
|
336
|
+
|
|
337
|
+
| Property | Type | Description |
|
|
338
|
+
|----------|--------|------------------------------------------------------------------------------------------|
|
|
339
|
+
| name | string | The name of the opening or variation (e.g., "Nimzo-Indian, 4.e3 O-O 5.Bd3 d5 6.Nf3 c5"). |
|
|
340
|
+
| eco | string | The ECO code (e.g., "E57", "B40"). |
|
|
341
|
+
|