chess-analysis-api
TypeScript icon, indicating that this package has built-in type declarations

1.1.3 • Public • Published

chess-analysis-api

chess engine that consume lichess API and wasm of stockfish for purpose a chess engine with hight level interface.

installation

npm install chess-analysis-api

or with yarn

yarn add chess-analysis-api

Usage

ES6 Syntax

import {chessAnalysisApi} from 'chess-analysis-api';

chessAnalysisApi.getAnalysis({

  // <https://en.wikipedia.org/wiki/Notation_Forsyth-Edwards>
  fen: "r1bqkb1r/pppp1ppp/2n2n2/1B2p3/4P3/5N2/PPPP1PPP/RNBQK2R w KQkq - 4 4",

  // calcul depth default=7
  depth: 12,

  // number options move should calcul
  multipv: 2
})
.then((result) => {

  console.log(result);
  // ...
})
.catch(error => {

  console.error(error);
  throw new Error(error.message);

  // ...
});

How this work

this package consume multiple providers:

And with a manager, the package calls for the best providers according to the FEN position, for sample if the FEN position indicates less than 10 moves played, the manager will call the provider of the openings. But if the FEN position indicates more than 35 moves already played the manager will not report the opening providers, nor the cloud assessment providers (because the cloud assessment providers only give results from their cache) and call directly the stockfish provider.

Advanced options

chess-analysis-api use 3 providers for Lichess API opening and Lichess API cloud not use parameter depth that represent calcul power of chess engine if you want full control of calcul power engine, you should exclude Lichess Provider and use only Stockfish provider.

Exemple:

import {chessAnalysisApi, PROVIDERS} from 'chess-analysis-api';


chessAnalysisApi.getAnalysis({

  // <https://en.wikipedia.org/wiki/Notation_Forsyth-Edwards>
  fen: "r1bqkb1r/pppp1ppp/2n2n2/1B2p3/4P3/5N2/PPPP1PPP/RNBQK2R w KQkq - 4 4",

  // calcul depth default=7
  depth: 12,

  // number options move should calcul
  multipv: 2,

  // excludes provider.s
  excludes: [
    PROVIDERS.LICHESS_BOOK,
    PROVIDERS.LICHESS_CLOUD_EVAL
  ]
})
.then((result) => {

  console.log(result);
  // ...
})
.catch(error => {

  console.error(error);
  throw new Error(error.message);

  // ...
});

typing result

See below result format as response of getAnalysis: (...arg) => Promise<AnalysisOutputType>:

export type AnalysisOutputProviderType = "lichess" | "stockfish";

export type AnalysisOutputActionType = "opening" | "eval";

export type AnalysisOutputLineScoreType = "cp" | "mate";
export type AnalysisOutputLineScore = {
  type: AnalysisOutputLineScoreType;
  value: number;
};

export type AnalysisOutputLineType = {

  // computer eval in centi-pawn view by white player
  score?: AnalysisOutputLineScore;

  // next moves (main line of computer)
  uci: string | string[];
};

export type AnalysisOutputType = {
  provider: AnalysisOutputProviderType;
  type: AnalysisOutputActionType;

  fen: string;

  // power calcul only for stockfish provider
  depth?: number;

  // number of lines
  multipv?: number;

  // opening data only for lichess opening provider
  opening?: {
    eco: string; // opening FIDE code
    name: string; // opening full name
  } | null,

  moves: AnalysisOutputLineType[];
};

Package Sidebar

Install

npm i chess-analysis-api

Weekly Downloads

0

Version

1.1.3

License

ISC

Unpacked Size

48.1 kB

Total Files

32

Last publish

Collaborators

  • orivoir21