Made using the 0x88 chess board representation.
Print an ASCII diagram of the current position.
Resets the board and imports the given FEN string.
Resets the chess board and imports a given PGN (Portable Game Notation) string. The method loads the FEN of the starting position from the PGN string, but does not import any subsequent moves.
const chessBoard = new ChessBoard();
chessBoard.loadPGN(`
[Event "?"]
[Site "?"]
[Date "1128.??.??"]
[Round "?"]
[White "White to move"]
[Black "?"]
[Result "1-0"]
[SetUp "1"]
[FEN "rn2rk2/5pp1/p7/2pb1qN1/7Q/2P5/5PPP/1R3RK1 w - - 0 1"]
[PlyCount "0"]
[SourceTitle "31 agosot 2018"]
[Source "Tipter Napoleon"]
[SourceDate "2018.08.31"]
[SourceVersion "1"]
[SourceVersionDate "2018.08.31"]
[SourceQuality "1"]
1-0
`)
Returns a boolean indicating whether a specific square is under attack by any piece belonging to a particular colour.
Returns a boolean indicating whether if the side to move is in check.
Returns a boolean indicating whether if the side to move has been checkmated.
Returns a boolean indicating whether if the side to move has been stalemated.
Returns a boolean indicating whether if there is no way to end the game in checkmate.
Returns a boolean indicating whether if there are three or more identical positions in the game history.
Returns a boolean indicating whether if isStaleMate
or isInsufficientMaterial
or isThreefoldRepetition
.
Returns a string that rappresents the current position.
const chessBoard = new ChessBoard();
chessBoard.movePiece({ fromSquare: Square.c2, toSquare: Square.c4 });
chessBoard.movePiece({ fromSquare: Square.e7, toSquare: Square.e5 });
chessBoard.getAscii();
// +-------------------------------+
// 8 | r | n | b | q | k | b | n | r |
// 7 | p | p | p | p | . | p | p | p |
// 6 | . | . | . | . | . | . | . | . |
// 5 | . | . | . | . | p | . | . | . |
// 4 | . | . | P | . | . | . | . | . |
// 3 | . | . | . | . | . | . | . | . |
// 2 | P | P | . | P | P | P | P | P |
// 1 | R | N | B | Q | K | B | N | R |
// +-------------------------------+
// a b c d e f g h
Returns the piece and color of the given square.
const chessBoard = new ChessBoard({ fen: '8/pN1b2Q1/8/5P2/2k2K2/6P1/8/7r w - - 0 1' });
chessBoard.getSquare(Square.e1); // { piece: 'K', color: 'w' }
chessBoard.getSquare(Square.e6); // { piece: 'e', color: 'b' }
Returns an array representation of the pieces on the board.
const chessBoard = new ChessBoard({ fen: '8/7P/4kbK1/5N2/8/8/8/8 w HAha - 0 1' });
chessBoard.getBoardPieces();
/*
[
{
"square": "h7",
"piece": "P",
"color": "w"
},
{
"square": "e6",
"piece": "k",
"color": "b"
},
{
"square": "f6",
"piece": "b",
"color": "b"
},
{
"square": "g6",
"piece": "K",
"color": "w"
},
{
"square": "f5",
"piece": "N",
"color": "w"
}
]
*/.
Returns list of legal moves based on the current position. An optional square can be specified to obtain the legal moves for that square.
const chessBoard = new ChessBoard({ fen: '8/7P/4kbK1/8/8/8/8/8 w - - 4 3' });
board.getLegalMoves(); // [ "h8", "h6, h5" ]
Returns a list of the current game's moves.
const chessBoard = new ChessBoard();
board.movePiece({ fromSquare: Square.c2, toSquare: Square.c4 });
board.movePiece({ fromSquare: Square.e7, toSquare: Square.e5 });
board.getHistory(); // [ "c4", "e5" ]
Returns a number indicating the current move.
Returns the FEN of the current position.
Returns separate scores for white and black players. Calculates the material advantage based on the current board state.
const chessBoard = new ChessBoard({ fen: '1k6/R5R1/2p5/2Ppp3/7p/NP2P1nP/5KP1/r7 w - - 3 34' });
chessBoard.getMaterialAdvantage(); // { w: 6, b: -6 }
Remove and return the piece on the give square.
const chessBoard = new ChessBoard('r3r1k1/p2qppbp/1n4p1/3b4/1QpP3B/4PN2/P3BPPP/1RR3K1 b - - 8 17');
chessBoard.remove(Square.h4) // { piece: 'B', color: 'w' }
Moves a piece from one square to another.
Undo the number of half-moves given in input. Defaults to 1.
Redo the number of half-moves given in input. Defaults to 1.
Remove every piece from the board. The new FEN will be: 8/8/8/8/8/8/8/8 w - - 0 1