KhepriChess is a chess engine written in TypeScript (JavaScript).
For instructions on using KhepriChess, see the Usage section below.
Why a chess engine in JavaScript? My goal here is simply to see what JS can do and learn something about chess engine programming along the way. And I wanted to try something that hadn't been done in a JS chess engine...
Unlike other JS chess engines, KhepriChess uses 64-bit bitboards for board representation. Prior to the introduction of BigInt
, JS was unable to represent integers larger than 32-bits. For chess bitboards, this meant having to use two 32-bit boards: one for the upper 32-bits and one for the lower 32-bits.
There is a trade-off, though, to using BigInt
. While it makes various aspects of programming a chess engine easier, the way BigInts are implemented in JS make them extremely slow (compared to regular Numbers). More on this can be found in this V8 blog post.
KhepriChess is only an engine and does not provide any sort of UI. For that, you can use it in a browser or a UCI-compatible GUI. A .js
file provided for browsers and prebuilt binaries for Windows, Linux, and Mac.
KhepriChess can be added with:
<script src="kheprichess_browser.js" />
or
import Engine from 'kheprichess_browser';
For a more in-depth example of using it in the browser, please see the the example page.
Follow the instructions for the particular GUI program on adding a new engine. Some free programs are:
KhepriChess supports the Chess960 (Fischer Random Chess) variant. To enable:
- Browser: set the
isChess960
property to true - UCI: Use the UCI option
KhepriChess supports the use of a polyglot opening book. Simply place a book file with the name of khepri_polyglot.bin
in the same directory that the JS file is running from and it will automatically detect and load it.
Please note: The browser version does not support polyglot.
A huge thanks to Maksim Korzh, aka Code Monkey King, and his video tutorial series on bitboards. Without it, I never would have gotten anywhere.
Also a huge thanks to everyone at the talkchess forums for providing value support and answers to my terrible questions.