Signature:
export declare class Chess
Constructor | Modifiers | Description |
---|---|---|
(constructor)(fen) | The Chess() constructor takes an optional parameter which specifies the board configuration in [Forsyth-Edwards Notation](http://en.wikipedia.org/wiki/Forsyth%E2%80%93Edwards\_Notation). |
Property | Modifiers | Type | Description |
---|---|---|---|
currentNode | readonly |
Readonly<TreeNode<GameState>> | |
header | HeaderMap | ||
hexTree | readonly |
Readonly<TreeNode<HexState>> | |
state | readonly |
Readonly<BoardState> | |
tree | readonly |
Readonly<TreeNode<GameState>> |
Method | Modifiers | Description |
---|---|---|
addNag(nag, key) | ||
ascii(newline_char) | Returns a string containing an ASCII diagram of the current position. | |
board() | Returns an 2D array representation of the current position. Empty squares are represented by null . |
|
clear(keepHeaders) | Clears the board. | |
deleteComment(key) | Delete and return the comment for a position, if it exists. | |
deleteComments() | Delete comments for all positions. | |
deleteNode(key) | Delete a node and its children from the tree. Cannot delete the root node. | |
fen(strict) | Returns the FEN string for the current position. | |
gameOver() | Returns true if the game has ended via checkmate, stalemate, draw, threefold repetition, or insufficient material. Otherwise, returns false. | |
getComment(key) | Retrieve the comment if it exists. | |
getComments(key) | Retrieve comments for all positions, keyed by FEN string. | |
getNags(key) | ||
getPiece(square) | Returns the piece on the square. | |
getPieces() | Returns a map of squares to pieces. | |
history(options) | Returns a list containing the moves of the current game. | |
history(options) | Returns a list containing the moves of the current game. | |
inCheck() | Returns true or false if the side to move is in check. | |
inCheckmate() | Returns true or false if the side to move has been checkmated. | |
inDraw() | Returns true or false if the game is drawn (50-move rule or insufficient material). | |
inStalemate() | Returns true or false if the side to move has been stalemated. | |
insufficientMaterial() | Returns true if the game is drawn due to insufficient material (K vs. K, K vs. KB, or K vs. KN) otherwise false. | |
inThreefoldRepetition() | Returns true or false if the current board position has occurred three or more times. | |
isAttacked(square, color) | Checks if a square is attacked by any piece | |
isAttacking(square, targetSquare) | Checks if a square is attacking a target square. | |
isPromotion(move) | Checks if a move results in a promotion. | |
isThreatening(square, targetSquare) | Checks if a square is threatening a target square. | |
load(fen, options) | Clears the board and loads the Forsyth–Edwards Notation (FEN) string. | |
loadPgn(pgn, options) | Load the moves of a game stored in [Portable Game Notation](http://en.wikipedia.org/wiki/Portable\_Game\_Notation). The The method will throw an error if the PGN was not parsed successfully. |
|
move(move, options) | Attempts to make a move on the board, returning a move object if the move was legal, otherwise null. The .move function can be called two ways, by passing a string in Standard Algebraic Notation (SAN): | |
moves(options) | Returns a list of legal moves from the current position. The function takes an optional parameter for filtering move generation. | |
pgn(options) | Returns the game in PGN format. Options is an optional parameter which may include max width and/or a newline character settings. | |
putPiece(piece, square) | Place a piece on the square where piece is an object with the form { type: ..., color: ... } . Returns true if the piece was successfully placed, otherwise, the board remains unchanged and false is returned. put() will fail when passed an invalid piece or square, or when two or more kings of the same color are placed. |
|
redo() | Redo mainline move. | |
redoAll() | Redo all mainline moves. | |
removePiece(square) | Remove and return the piece on square . |
|
reset() | Reset the board to the initial starting position. | |
sanMoves(options) | Returns a list of legal moves from the current position. The function takes an optional parameter for filtering move generation. | |
setComment(comment, key) | Comment on a position, if it exists. | |
setCurrentNode(key) | ||
squareColor(square) | Returns the color of the square ('light' or 'dark'). | |
turn() | Returns the current side to move. | |
undo() | Takeback the last half-move, returning a move object if successful, otherwise null. | |
undoAll() | Undo all moves. | |
validateFen(fen, options) | Returns a object mapping FEN validation errors to error message. | |
validateMoves(moves) | Validates a sequence of moves, returning an array of move objects if the moves are all legal, otherwise null. |