chess4js 1.0.0-beta.4 → 1.0.0-beta.6
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 +42 -38
- package/chess4js.d.mts +3 -0
- package/chess4js.mjs +1096 -958
- package/chess4js.mjs.map +1 -1
- package/kotlin-kotlin-stdlib.mjs +17 -17
- package/kotlin-kotlin-stdlib.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
**Chess4js** is a JavaScript transpilation of **Chess4kt**, my Kotlin Multiplatform chess library.
|
|
9
9
|
|
|
10
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. At present, initialization takes approximately a few
|
|
11
|
+
functional, initialization performance is still being optimized. At present, initialization takes approximately a few
|
|
12
12
|
hundred milliseconds on modern machines.
|
|
13
13
|
|
|
14
14
|
---
|
|
@@ -65,19 +65,20 @@ A non-directly instantiable class representing a 64-bit bitboard. Instances are
|
|
|
65
65
|
|
|
66
66
|
### Methods
|
|
67
67
|
|
|
68
|
-
| Method | Arguments | Return Type
|
|
69
|
-
|
|
70
|
-
| peekLastBit | None | Bitboard
|
|
71
|
-
| peekFirstBit | None | Bitboard
|
|
72
|
-
| trailingZeros | None | number
|
|
73
|
-
| leadingZeros | None | number
|
|
74
|
-
| and | other: Bitboard | Bitboard
|
|
75
|
-
| or | other: Bitboard | Bitboard
|
|
76
|
-
| xor | other: Bitboard | Bitboard
|
|
77
|
-
| inv | None | Bitboard
|
|
78
|
-
| shl | i: number | Bitboard
|
|
79
|
-
| ushr | i: number | Bitboard
|
|
80
|
-
| toString | none | string
|
|
68
|
+
| Method | Arguments | Return Type | Description |
|
|
69
|
+
|---------------|-----------------|-------------------------|---------------------------------------------------------------------------------------------|
|
|
70
|
+
| peekLastBit | None | Bitboard | Returns a bitboard containing only the Least Significant Bit (LSB). |
|
|
71
|
+
| peekFirstBit | None | Bitboard | Returns a bitboard containing only the Most Significant Bit (MSB). |
|
|
72
|
+
| trailingZeros | None | number | Returns the number of zero bits following the LSB. |
|
|
73
|
+
| leadingZeros | None | number | Returns the number of zero bits preceding the MSB. |
|
|
74
|
+
| and | other: Bitboard | Bitboard | Performs a bitwise AND operation. |
|
|
75
|
+
| or | other: Bitboard | Bitboard | Performs a bitwise OR operation. |
|
|
76
|
+
| xor | other: Bitboard | Bitboard | Performs a bitwise XOR operation. |
|
|
77
|
+
| inv | None | Bitboard | Performs a bitwise NOT operation (inverts all bits). |
|
|
78
|
+
| shl | i: number | Bitboard | Returns a bitboard with bits shifted left by i positions. |
|
|
79
|
+
| ushr | i: number | Bitboard | Returns a bitboard with bits shifted right (unsigned) by `i` positions. |
|
|
80
|
+
| toString | none | string | Returns a formatted string representation. |
|
|
81
|
+
| toArray | none | ReadonlyArray\<number\> | Returns an array containing the indices of all set bits (bits equal to 1) in this bitboard. |
|
|
81
82
|
|
|
82
83
|
Instances of this class can be obtained from `Position` instances.
|
|
83
84
|
|
|
@@ -186,7 +187,8 @@ A utility class designed to group a `Position` and a `Move` together.
|
|
|
186
187
|
## Notation
|
|
187
188
|
|
|
188
189
|
This non-instantiable class represents the types of move notation supported by this library.
|
|
189
|
-
The library provides two predefined instances: `UCI` (long algebraic notation used in the UCI protocol) and `SAN` (
|
|
190
|
+
The library provides two predefined instances: `UCI` (long algebraic notation used in the UCI protocol) and `SAN` (
|
|
191
|
+
standard
|
|
190
192
|
algebraic notation).
|
|
191
193
|
|
|
192
194
|
### Properties
|
|
@@ -236,29 +238,31 @@ For the `Node` class:
|
|
|
236
238
|
|
|
237
239
|
### Methods
|
|
238
240
|
|
|
239
|
-
For the
|
|
240
|
-
|
|
241
|
-
| Method | Arguments | Return type | Description
|
|
242
|
-
|
|
243
|
-
| setTag | name: String, value: String | undefined | Sets a tag pair (name and value).
|
|
244
|
-
| getTag | name: String | Nullable<String> | Retrieves the tag's value.
|
|
245
|
-
| toString | None | String | Returns the game in pgn format.
|
|
246
|
-
| 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.
|
|
247
|
-
| 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.
|
|
248
|
-
| 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.
|
|
249
|
-
| 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.
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
|
257
|
-
|
|
|
258
|
-
|
|
|
259
|
-
|
|
|
260
|
-
|
|
|
261
|
-
|
|
|
241
|
+
For the `Game` class
|
|
242
|
+
|
|
243
|
+
| Method | Arguments | Return type | Description |
|
|
244
|
+
|---------------------|------------------------------------|------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
245
|
+
| setTag | name: String, value: String | undefined | Sets a tag pair (name and value). |
|
|
246
|
+
| getTag | name: String | Nullable<String> | Retrieves the tag's value. |
|
|
247
|
+
| toString | None | String | Returns the game in pgn format. |
|
|
248
|
+
| 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. |
|
|
249
|
+
| 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. |
|
|
250
|
+
| 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. |
|
|
251
|
+
| 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. |
|
|
252
|
+
| updateEco | None | undefined | Updates the instance's ECO ranking based on the last move of the main line. In match mode this is automatic, but in analysis this function must be called, otherwise the game will not be ranked. |
|
|
253
|
+
|
|
254
|
+
For the `Node` class
|
|
255
|
+
|
|
256
|
+
| Method | Arguments | Return type | Description |
|
|
257
|
+
|-------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
258
|
+
| 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. |
|
|
259
|
+
| promoteChild | index: number | boolean | Promotes the child at the given index to the primary variation (children[0]). |
|
|
260
|
+
| promoteNode | None | boolean | Promotes this node to the main line. |
|
|
261
|
+
| removeChild | node: Node | boolean | Removes the specified child node (variation) from the current node's list of children. |
|
|
262
|
+
| hasChildren | None | boolean | Checks if the node has children. |
|
|
263
|
+
| belongsToMainLine | None | boolean | Indicates whether this node belongs to the main line (i.e., it is the first child of all its ancestors). |
|
|
264
|
+
| 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. |
|
|
265
|
+
| toSan | language: string (deafult "english"), pieces: Nullable\<Array\<String\>\> (default null) | string | Converts a move to Standard Algebraic Notation (SAN). This function acts as a convenience wrapper to generate notation adapted to different languages. If the move is null, it returns an empty string. If the specified language is not predefined, a custom array of piece initials must be provided. Supported internal languages: "english", "spanish", "dutch", "french", "german", and "italian". |
|
|
262
266
|
|
|
263
267
|
### Factories and PGN parsing
|
|
264
268
|
|
package/chess4js.d.mts
CHANGED
|
@@ -13,6 +13,7 @@ export declare class Bitboard {
|
|
|
13
13
|
inv(): Bitboard;
|
|
14
14
|
shl(i: number): Bitboard;
|
|
15
15
|
ushr(i: number): Bitboard;
|
|
16
|
+
toArray(): ReadonlyArray<number>;
|
|
16
17
|
}
|
|
17
18
|
/** @deprecated $metadata$ is used for internal purposes, please don't use it in your code, because it can be removed at any moment */
|
|
18
19
|
export declare namespace Bitboard.$metadata$ {
|
|
@@ -70,6 +71,7 @@ export declare class Game {
|
|
|
70
71
|
deleteFromExclusive(node: Node): Node;
|
|
71
72
|
deleteFromInclusive(node: Node): Node;
|
|
72
73
|
deleteBefore(_this_: Game, node: Node): Node;
|
|
74
|
+
updateEco(): void;
|
|
73
75
|
}
|
|
74
76
|
/** @deprecated $metadata$ is used for internal purposes, please don't use it in your code, because it can be removed at any moment */
|
|
75
77
|
export declare namespace Game.$metadata$ {
|
|
@@ -109,6 +111,7 @@ export declare class Node {
|
|
|
109
111
|
hashCode(): number;
|
|
110
112
|
equals(other: Nullable<any>): boolean;
|
|
111
113
|
toString(): string;
|
|
114
|
+
toSan(language?: string, pieces?: Nullable<Array<string>>): string;
|
|
112
115
|
}
|
|
113
116
|
/** @deprecated $metadata$ is used for internal purposes, please don't use it in your code, because it can be removed at any moment */
|
|
114
117
|
export declare namespace Node.$metadata$ {
|