npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

chess-analysis-api

v1.1.3

Published

chess engine hight level api

Downloads

15

Readme

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[];
};