Chess Engine Battles & Analysis using UCI Engines

Overview

Chess Engine Battles & Analysis

Written in TypeScript, using UCI Engine, managed from NodeJS

Tested using Stockfish, LCZero, Beserk and SmallBrain for Windows and Linux
Also compatibile with Stockfish WASM ports like 1 or 2

Modes

Analyze

npm run analyze sample/sample-white.pgn

  • Initializes UCI engine given specific options in analyze.json
    Note: default is built-in lightweight Stockfish Classic WASM
  • Runs every move through the chess engine
  • Calculates per-move centipawn loss,
    average centipawn loss,
    looks up openings according to ECO database,
    finds missed mates,
    notes mistakes/blunders/etc.
  • Optionally looks up Syzygy end-game tablebases
  • Can be used to analyze single game or run in batch

Battle

npm run battle

  • Initializes two UCI engines given specific options in battle.json
    and runs number of simulated games from either default or given position
  • Looks up openings used according to ECO database
    and further annotates games as they are played
  • Optionally looks up Syzygy end-game tablebases
  • Generates final output in PGN format

Engine Configuration Examples

as used in analyze.json and battle.json...

// stockfish 15 with nnue and syzygy database
{ "maxTime": 25, "engine": "engine/stockfish-15/sf15-bmi2", "nnue": "nn-6877cd24400e.nnue", "syzygy": "engine/syzygy" }, 
// stockfish 11 small // included!
{ "maxTime": 25, "engine": "engine/stockfish-11/stockfish_20011801_linux" }, 
// beserker 10 with nnue
{ "maxTime": 25, "engine": "engine/beserk/berserk-10-x64-avx2.exe", "nnue": "engine/beserk/berserk-c982d9682d4e.nn" }
// lczero with cuda execution
{ "maxTime": 25, "engine": "engine/leela/lc0-0.28.2-cuda.exe" },
// tiny stockfish classical as wasm from lichess-org // included!
{ "depth": 10, "engine": "../engine/lichess-org/stockfish.js", "type": "wasm" }
// full stockfish classical as wasm from hi-ogawa
{ "depth": 10, "engine": "../engine/hi-ogawa/stockfish.js", "type": "wasm" }

Code

  • src/battle.ts => dist/battle.js
    app that pairs two engines against each other and generates a game PGN

    • src/battle-play.ts module
      runs moves for both engines
      annotates each moves
  • src/analyze.ts => dist/analyze.js
    app that analyzes given game(s) in PGN format

    • src/analyze-game.ts module
      analyzes pgn
      generates and translates individual moves
      sends moves to engine and to be analyzed
      annotate results
  • src/uci.ts
    class that handles uci protocol communication

    • src/engine.ts
      initializes process-based on wasm-based engine
      and creates input/output channel
  • src/generate-openings.js => openings.json
    downloads latest eco openings and generates database

Note: All sources are compiled using @vladmandic/build CI tool

npm run build


WASM .vs. External Process

  • WASM
    Stockfish modules can be dynamically imported and used, but with some limitations as execution is still primarily single-threaded
    As a result, do not rely on engine maxTime parameter as engine may not be able to respond to stop analysis requests after specific time
    Instead, set reasonable value for depth parameter which automatically finishes move analysis as desired depth is reached

    For the same reason, threads and nnue options are currently not supported

    But this is simplest option to try this library as simple Stockfish WASM engine is included in the distribution
    Also this allows for execution on otherwise unsupported platforms where UCI binaries may not be readily available

  • External Process Execution is much more flexible as each process runs independently
    Just make sure to download binaries that can be executed on your platform!

    Btw, if you're using WSL, you can use either Linux or Windows builds without differences
    since Stockfish is statically linked and process spawning will handle it automatically


ECO and Syzygy Databases

  • ECO chess openings database is automatically generated from LiChess Repository
  • Syzygy endgame tablebases are provided for 4-move combination, but you can provide any variation up to massive 7-move solutions

Docs

Todo

  • Remove local-tree dependencies
You might also like...

JavaScript package for predictive data analysis and machine learning

scikit.js JavaScript package for predictive data analysis and machine learning. Generic math operations are powered by Tensorflowjs core layer. We are

Jan 6, 2023

A lightweight framework for data analysis in JavaScript.

A lightweight framework for data analysis in JavaScript.

datakit About A lightweight library/framework for data analysis in JavaScript. Usage npm install datakitjs --save Documentation & Examples Reading, Fi

Jun 26, 2021

Nouns On-Chain Proposal Simulation and Analysis

Nouns Diligence Nouns On-Chain Proposal Simulation and Analysis For Voters Technical reports for all reviewed proposals can be found in the reports fo

Dec 26, 2022

ec0lint - a static code analysis tool

ec0lint is a static code analysis tool that provides the users with useful hints on how to reduce the digital footprint of their webpages during the development process. Applying code changes suggested by ec0lint will make result with webpages that emit less carbon per visit, load quicker and are more space- efficient. The tool is open-source and community-driven.

Dec 5, 2022

A crawler that crawls the site's internal links, fetching information of interest to any SEO specialist to perform appropriate analysis on the site.

Overview 📝 It is a module that crawls sites and extracts basic information on any web page of interest to site owners in general, and SEO specialists

Apr 22, 2022

A quick and easy to use security reconnaissance webapp tool, does OSINT, analysis and red-teaming in both passive and active mode. Written in nodeJS and Electron.

A quick and easy to use security reconnaissance webapp tool, does OSINT, analysis and red-teaming in both passive and active mode. Written in nodeJS and Electron.

ᵔᴥᵔ RedJoust A quick and easy to use security reconnaissance webapp tool, does OSINT, analysis and red-teaming in both passive and active mode. Writte

Oct 31, 2022

A crawler that crawls the site's internal links, fetching information of interest to any SEO specialist to perform appropriate analysis on the site.

Overview 📝 It is a module that crawls sites and extracts basic information on any web page of interest to site owners in general, and SEO specialists

Apr 22, 2022

A Cli that handles the creation of a basic express App that supports Husky configuration & static analysis tools

A Cli that handles the creation of a basic express App that supports Husky configuration & static analysis tools

@phazero/create-express-app · Create express app is a CLI that can generate boiler plate code for setting up an express app. Installation & Usage npx

Oct 29, 2022

⚡ Archive of all Zotero Translators co-created by participants of the Information Analysis course in 2018 to date.

awesome-translators 1. awesome-translators 维护小组 1.1 Translators 更新流程 1.2 Zotero 安装流程 1.3 Zotero 进阶资料 2. Translators 2.1 Translators 总览表 2.2 Translator

Dec 30, 2022
Owner
Vladimir Mandic
Vladimir Mandic
Example Breakout games using small libraries/engines/templates for the js13kGames competition.

js13kBreakouts We implemented the same breakout style game with small libraries/engines/templates for the js13kGames competition! Live Demos LittleJS

js13kGames 16 Sep 17, 2022
A webXdc chess game for two players and many observers :)

Chess Board A webXdc chess game for two players, made with chess.js and chessboard.js Testing To test the app you can simply open the index.html file.

Asiel Díaz Benítez 6 Jun 30, 2022
Automatically add and keep up to date your latest games from chess.com

Chess Stats Action Automatically add and keep up to date your latest games from chess.com. Type Rapid ⏲️ Blitz ⚡ Bullet ?? Current 2805 3207 3300 Best

Leonardo Montini 10 Nov 12, 2022
♟️ Simple 2D Chess game

♟️ Chess2D A simple 2D Chess game made using HTML, CSS, and TypeScript. Chess2D This project uses the VanillaTilt.js library to achieve the 3D-paralla

null 6 Jul 22, 2022
⚡⚙️ Fast prototyping with template engines and integrated frontend tools. Vituum is a small wrapper around Vite.

⚡ ⚙️ Vituum Still in early development. Fast prototyping with template engines and integrated frontend tools ⚡ Vite integrated ??️ Fast prototyping ??

Vituum 103 Jan 3, 2023
Code Scanning/SAST/Static Analysis/Linting using many tools/Scanners with One Report - Scanmycode Community Edition (CE)

Star it If you like it, please give it a GitHub star/fork/contribute. This will ensure continous development ⭐ TLDR; To install it. Install docker and

Marcin Kozlowski 351 Dec 29, 2022
Scrape tweets from Twitter search results based on keywords and date range using Playwright. Save scraped tweets in a CSV file for easy analysis

Tweet Harvest (Twitter Crawler) Tweet Harvest is a command-line tool that uses Playwright to scrape tweets from Twitter search results based on specif

Helmi Satria 33 Aug 9, 2023
The project integrates workflow engine, report engine and organization authority management background, which can be applied to the development of OA, HR, CRM, PM and other systems. With tlv8 IDE, business system development, testing and deployment can be realized quickly.

介绍 项目集成了工作流引擎、报表引擎和组织机构权限管理后台,可以应用于OA、HR、CRM、PM等系统开发。配合使用tlv8 ide可以快速实现业务系统开发、测试、部署。 后台采用Spring MVC架构简单方便,前端使用流行的layui界面美观大方。 采用组件开发技术,提高系统的灵活性和可扩展性;采

Qian Chen 38 Dec 27, 2022
A github action that provides detailed bundle analysis on PRs for next.js apps

Next.js Bundle Analysis Github Action Analyzes each PR's impact on your next.js app's bundle size and displays it using a comment. Optionally supports

HashiCorp 369 Dec 27, 2022
Team project within the course of Software System Design and Analysis.

?? InnoBookCrossing - Application for sharing books at Innopolis gh-md-toc ?? General Information Description The application is designed to help peop

Dariya 33 Oct 22, 2022