chess4js 1.0.0-beta.5 → 1.0.0-beta.7

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 CHANGED
@@ -82,6 +82,15 @@ A non-directly instantiable class representing a 64-bit bitboard. Instances are
82
82
 
83
83
  Instances of this class can be obtained from `Position` instances.
84
84
 
85
+ ### Visible squares
86
+
87
+ The visibleSquares function accepts a piece type, a source square, and the current board position to compute the
88
+ visibility bitmask, returning the result as a Bitboard.
89
+
90
+ | Function | Arguments | Return Type | Description |
91
+ |----------------|---------------------------------------------------|-------------|------------------------------------------------------------------------------------------------------|
92
+ | visibleSquares | piece: string, square: string, position: Position | Bitboard | Calculates a bitboard of all squares "visible" or attacked by an specific piece from a given square. |
93
+
85
94
  ## Move
86
95
 
87
96
  A non directly instantiable class that represents a move made on the board.
@@ -153,6 +162,8 @@ const somePosition = positionOf("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w K
153
162
  | 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. |
154
163
  | gameOver | boolean | True if the game state is concluded (terminal position), either due to a forced draw or checkmate. False otherwise. |
155
164
  | sideToMove | Side | The side (WHITE or BLACK) whose turn it is to move. |
165
+ | friends | Bitboard | Returns a bitboard representing the occupancy of all friendly pieces. |
166
+ | enemies | Bitboard | Returns a bitboard representing the occupancy of all enemy pieces. |
156
167
 
157
168
  ### Methods
158
169
 
@@ -165,6 +176,7 @@ const somePosition = positionOf("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w K
165
176
  | 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. |
166
177
  | 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. |
167
178
  | toString | None | string | retrieves a nice string representation |
179
+ | flipSide | None | Position | Creates a new Position identical to the current one, but with the active side toggled. |
168
180
 
169
181
  ### Factories
170
182
 
@@ -240,27 +252,29 @@ For the `Node` class:
240
252
 
241
253
  For the `Game` class
242
254
 
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
-
255
+ | Method | Arguments | Return type | Description |
256
+ |---------------------|------------------------------------|------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
257
+ | setTag | name: String, value: String | undefined | Sets a tag pair (name and value). |
258
+ | getTag | name: String | Nullable<String> | Retrieves the tag's value. |
259
+ | toString | None | String | Returns the game in pgn format. |
260
+ | 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. |
261
+ | 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. |
262
+ | 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. |
263
+ | 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. |
264
+ | 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. |
265
+
253
266
  For the `Node` class
254
267
 
255
- | Method | Arguments | Return type | Description |
256
- |-------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
257
- | 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. |
258
- | promoteChild | index: number | boolean | Promotes the child at the given index to the primary variation (children[0]). |
259
- | promoteNode | None | boolean | Promotes this node to the main line. |
260
- | removeChild | node: Node | boolean | Removes the specified child node (variation) from the current node's list of children. |
261
- | hasChildren | None | boolean | Checks if the node has children. |
262
- | belongsToMainLine | None | boolean | Indicates whether this node belongs to the main line (i.e., it is the first child of all its ancestors). |
263
- | 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. |
268
+ | Method | Arguments | Return type | Description |
269
+ |-------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
270
+ | 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. |
271
+ | promoteChild | index: number | boolean | Promotes the child at the given index to the primary variation (children[0]). |
272
+ | promoteNode | None | boolean | Promotes this node to the main line. |
273
+ | removeChild | node: Node | boolean | Removes the specified child node (variation) from the current node's list of children. |
274
+ | hasChildren | None | boolean | Checks if the node has children. |
275
+ | belongsToMainLine | None | boolean | Indicates whether this node belongs to the main line (i.e., it is the first child of all its ancestors). |
276
+ | 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. |
277
+ | 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". |
264
278
 
265
279
  ### Factories and PGN parsing
266
280
 
package/chess4js.d.mts CHANGED
@@ -14,6 +14,8 @@ export declare class Bitboard {
14
14
  shl(i: number): Bitboard;
15
15
  ushr(i: number): Bitboard;
16
16
  toArray(): ReadonlyArray<number>;
17
+ bitCount(): number;
18
+ equals(other: Nullable<any>): boolean;
17
19
  }
18
20
  /** @deprecated $metadata$ is used for internal purposes, please don't use it in your code, because it can be removed at any moment */
19
21
  export declare namespace Bitboard.$metadata$ {
@@ -71,6 +73,7 @@ export declare class Game {
71
73
  deleteFromExclusive(node: Node): Node;
72
74
  deleteFromInclusive(node: Node): Node;
73
75
  deleteBefore(_this_: Game, node: Node): Node;
76
+ updateEco(): void;
74
77
  }
75
78
  /** @deprecated $metadata$ is used for internal purposes, please don't use it in your code, because it can be removed at any moment */
76
79
  export declare namespace Game.$metadata$ {
@@ -110,6 +113,7 @@ export declare class Node {
110
113
  hashCode(): number;
111
114
  equals(other: Nullable<any>): boolean;
112
115
  toString(): string;
116
+ toSan(language?: string, pieces?: Nullable<Array<string>>): string;
113
117
  }
114
118
  /** @deprecated $metadata$ is used for internal purposes, please don't use it in your code, because it can be removed at any moment */
115
119
  export declare namespace Node.$metadata$ {
@@ -198,12 +202,15 @@ export declare class Position {
198
202
  get enPassantSquare(): Nullable<Square>;
199
203
  get gameOver(): boolean;
200
204
  get sideToMove(): Side;
205
+ get friends(): Bitboard;
206
+ get enemies(): Bitboard;
201
207
  whiteLacksOfMaterial(): boolean;
202
208
  blackLacksOfMaterial(): boolean;
203
209
  pieceAt(square: Square): Piece;
204
210
  isLegal(move: Move): boolean;
205
211
  move(move: Move): Position;
206
212
  moveFromString(move: string, notation?: Notation): Position;
213
+ flipSide(): Position;
207
214
  hashCode(): number;
208
215
  equals(other: Nullable<any>): boolean;
209
216
  toString(): string;
@@ -355,4 +362,5 @@ export declare function moveOf(move: string): Move;
355
362
  export declare function analysisGame(idSupplier?: () => Nullable<any>): Game;
356
363
  export declare function strictMatch(idSupplier?: () => Nullable<any>): Game;
357
364
  export declare function customGame(gameMode: string, threeRepetitionsMode: string, fiftyMovesRuleMode: string, initialFen?: Nullable<string>, idSupplier?: () => Nullable<any>): Game;
358
- export declare function parseGames(pgnInput: string, idSupplier?: () => Nullable<any>): ReadonlyArray<Game>;
365
+ export declare function parseGames(pgnInput: string, idSupplier?: () => Nullable<any>): ReadonlyArray<Game>;
366
+ export declare function visibleSquares(piece: string, square: string, position: Position): Bitboard;