chess-legal-moves
TypeScript icon, indicating that this package has built-in type declarations

2.3.2 • Public • Published

♔ Chess legal moves

Contributor Covenant

Analyses a given chess game position in Fen notation to return legal moves and provides the next game position after a given move

API reference

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;

Readme

Keywords

Package Sidebar

Install

npm i chess-legal-moves

Weekly Downloads

79

Version

2.3.2

License

MIT

Unpacked Size

111 kB

Total Files

75

Last publish

Collaborators

  • colinfaivre