chess-legal-moves
v2.3.2
Published
Analyses a given chess game position in Fen notation to return legal moves and provides the next game position after a given move
Downloads
377
Readme
♔ Chess legal moves
Analyses a given chess game position in Fen notation to return legal moves and provides the next game position after a given move
This lib exposes a Game class, its constructor takes a string representing a snapshot of a chess game in FEN notation. You can then use legalMoves, kingState properties and addMove() method.
legalMoves property is an array containing all legal moves in UCI notation
kingState property gives you the state of the game (isCheck, isCheckmated, isDraw).
Installation
- with npm
npm install chess-legal-moves
- with yarn
yarn add chess-legal-moves
Usage
Import the Game class from the library and pass its constructor a FEN string. As an example the following FEN string represents a game starting position. Learn about FEN notation
import Game from 'chess-legal-moves';
const game = new Game('rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1');
const possibleMoves = game.legalMoves;
const kingState = game.kingState;