new(‐ish) engine in JavaScript (Deno) + APIs

Discussion of chess software programming and technical issues.

Moderator: Ras

zamfofex
Posts: 26
Joined: Wed Feb 16, 2022 6:21 am
Full name: P. M. Zamboni

new(‐ish) engine in JavaScript (Deno) + APIs

Post by zamfofex »

Hello, everyone! I’m new in this forum (as you might be able to tell for my post count). It has been quite a while since I have last used a forum like this, even!

Last year, I started working on a chess bot for Lichess, and I feel like I got it to a fairly advanced stage now! It isn’t the best, but I’m quite content with how it plays!

I wrote it in JavaScript targetting Deno, but I was able to run it directly on a browser as well as through ‘qjsc’ (from QuickJS, with some shimming).

Besides just the engine/AI, the project also features an API for interacting with Lichess and chess boards/games from JavaScript/TypeScript on Deno (and elsewhere) that I came up with myself! I also wrote some fairly thorough documentation of all the modules that you can use from other projects. (Note: I try to avoid changing the API gratuitously, but I also don’t want to commit to it, just in case I want to change it later.)

I also wrote a Discord bot that allows you to play the bot on Discord in a server or through DMs, and also a (currently simplistic) UCI front end for it, both found in the “more stuff” section in the readme.

The AI algorithm is extremely simplistic, it is just a shallow minimax algorithm using the material count and taking in consideration mobility. (Though I have changed it multiple times.)

Any kinds of thoughts and suggestions about the project would be appreciated!

Edit: I forgot to link the project, what a dummy! :oops:
https://github.com/zamfofex/dummyette
User avatar
mvanthoor
Posts: 1784
Joined: Wed Jul 03, 2019 4:42 pm
Location: Netherlands
Full name: Marcel Vanthoor

Re: new(‐ish) engine in JavaScript (Deno) + APIs

Post by mvanthoor »

Welcome :)
zamfofex wrote: Sat Feb 19, 2022 12:46 pm Hello, everyone! I’m new in this forum (as you might be able to tell for my post count). It has been quite a while since I have last used a forum like this, even!
Some old ways of doing things are cool, aren't they? In forums such as this, you can find 20 years of information floating around on hundreds of different topics. Try that with Facebook groups, twitter, or Discord... (Hopefully somebody/the owners have a backup in case this ever gets lost.) There's even more information in the predecessor of this forum: the CCC newsgroup, which can be found through Google Groups (and Google itself).
Last year, I started working on a chess bot for Lichess, and I feel like I got it to a fairly advanced stage now! It isn’t the best, but I’m quite content with how it plays!
Great :) I hope there's an easy way of downloading/playing against it. I'll have a look at the Github link.
Author of Rustic, an engine written in Rust.
Releases | Code | Docs | Progress | CCRL
zamfofex
Posts: 26
Joined: Wed Feb 16, 2022 6:21 am
Full name: P. M. Zamboni

Re: new(‐ish) engine in JavaScript (Deno) + APIs

Post by zamfofex »

mvanthoor wrote: Sat Feb 19, 2022 1:58 pm Welcome :)

[…]

Some old ways of doing things are cool, aren't they? In forums such as this, you can find 20 years of information floating around on hundreds of different topics. […]
Indeed! As I said, it has been a while since I’ve interacted in a forum like this, so this is a very refreshing experience to me!
mvanthoor wrote: Sat Feb 19, 2022 1:58 pm Great :) I hope there's an easy way of downloading/playing against it. I'll have a look at the Github link.
You can always play the bot on Lichess. (Or at least should be able to!) Other than that, you can investigate the “Dummyette in your browser” link in the “more stuff” section of the readme. That should be fairly trivial to set up if you have Git and an HTTP server readily available (like Python’s).

If you do get around playing it, thoughts on how it went would be appreciated!
Guenther
Posts: 4718
Joined: Wed Oct 01, 2008 6:33 am
Location: Regensburg, Germany
Full name: Guenther Simon

Re: new(‐ish) engine in JavaScript (Deno) + APIs

Post by Guenther »

mvanthoor wrote: Sat Feb 19, 2022 1:58 pm Welcome :)

... you can find 20 years of information floating around on hundreds of different topics. Try that with Facebook groups, twitter, or Discord... (Hopefully somebody/the owners have a backup in case this ever gets lost.) There's even more information in the predecessor of this forum: the CCC newsgroup, which can be found through Google Groups (and Google itself).
Just a little nitpicking Marcel, the CCC newsgroup is not the predecessor of this forum, but the 'grandfather' of this forum.
This one is the predecessor (archived by Sean Mintz):

https://www.stmintz.com/ccc/index.php?
https://rwbc-chess.de

[Trolls n'existent pas...]
zamfofex
Posts: 26
Joined: Wed Feb 16, 2022 6:21 am
Full name: P. M. Zamboni

Re: new(‐ish) engine in JavaScript (Deno) + APIs

Post by zamfofex »

I have stopped working on Dummyette to work on a different project for the past month, but I have been thinking about picking it back up again some time soon. (But I’m still unsure.) Some more thoughts about it:
  • I know the actual AI algorithm is extremely simplistic. My hope with it was to try to create an algorithm that balances simplicity and effectiveness. I know that this is a subjective goal, but I feel like I was really happy with how it turned out. I received a lot of help and advice from someone I met in a Discord server, and that helped simultaneously improve it and also simplify it! My goal is to optimize it for playing games against humans, rather than other bots. (Even though it isn’t the best, it is relatively fine against lower rated layers.)
  • I considered implementing something like PeSTO’s evaluation function. (And in fact I did at some point.) But I decided against publishing those changes, because it wasn’t something I came up with (or helped come up with), so it didn’t feel like it was an improvement that was satisfying to me.
  • I also tried investigating incorporating NNUE data at some point. I found that the file format for Stockfish’s NNUE files are severely undocumented, so I had to reverse‐engineer existing implementations to figure out how they worked. I also found that the format changed very frequently, so it was difficult to know which information I had was up‐to‐date, and which was outdated. Another issue I ran into is that it is difficult to optimize it effectively without either explicitly using SIMD builtins (in C or C++) or using a compiler that optimizes code to use them. I wrote a test implementation in JavaScript to see how well I understood the format, and it seemed to work (albeit really slowly), but then literally the next day a new Stockfish NNUE file was released, and my parser wasn’t able to understand it. That (alongside the “I didn’t come up with it myself” issue I mentioned above) put me off using NNUE for my project.
However, all the problems aside, and the algorithm’s simplicity aside too, I feel like Dummyette actually works really well as a library and set of tools for people trying to write chess bots and interfaces in JavaScript. As I said, I put a lot of effort into documenting how everything works, and also making sure that it is really convenient. Of course I am biased, but I feel like working with Dummyette’s APIs was always a pleasure to me given how much thought I put into designing it.

I know JavaScript is an unpopular choice for a chess bot or chess tools, but I like to say that it worked out really well for me! If anyone has any thoughts to share, I’d love to hear what other people think about it!
supersharp77
Posts: 1262
Joined: Sat Jul 05, 2014 7:54 am
Location: Southwest USA

Re: new(‐ish) engine in JavaScript (Deno) + APIs

Post by supersharp77 »

zamfofex wrote: Tue Mar 22, 2022 7:37 pm I have stopped working on Dummyette to work on a different project for the past month, but I have been thinking about picking it back up again some time soon. (But I’m still unsure.) Some more thoughts about it:
  • I know the actual AI algorithm is extremely simplistic. My hope with it was to try to create an algorithm that balances simplicity and effectiveness. I know that this is a subjective goal, but I feel like I was really happy with how it turned out. I received a lot of help and advice from someone I met in a Discord server, and that helped simultaneously improve it and also simplify it! My goal is to optimize it for playing games against humans, rather than other bots. (Even though it isn’t the best, it is relatively fine against lower rated layers.)
  • I considered implementing something like PeSTO’s evaluation function. (And in fact I did at some point.) But I decided against publishing those changes, because it wasn’t something I came up with (or helped come up with), so it didn’t feel like it was an improvement that was satisfying to me.
  • I also tried investigating incorporating NNUE data at some point. I found that the file format for Stockfish’s NNUE files are severely undocumented, so I had to reverse‐engineer existing implementations to figure out how they worked. I also found that the format changed very frequently, so it was difficult to know which information I had was up‐to‐date, and which was outdated. Another issue I ran into is that it is difficult to optimize it effectively without either explicitly using SIMD builtins (in C or C++) or using a compiler that optimizes code to use them. I wrote a test implementation in JavaScript to see how well I understood the format, and it seemed to work (albeit really slowly), but then literally the next day a new Stockfish NNUE file was released, and my parser wasn’t able to understand it. That (alongside the “I didn’t come up with it myself” issue I mentioned above) put me off using NNUE for my project.
However, all the problems aside, and the algorithm’s simplicity aside too, I feel like Dummyette actually works really well as a library and set of tools for people trying to write chess bots and interfaces in JavaScript. As I said, I put a lot of effort into documenting how everything works, and also making sure that it is really convenient. Of course I am biased, but I feel like working with Dummyette’s APIs was always a pleasure to me given how much thought I put into designing it.

I know JavaScript is an unpopular choice for a chess bot or chess tools, but I like to say that it worked out really well for me! If anyone has any thoughts to share, I’d love to hear what other people think about it!
Well...haven't looked at your Github page yet..has anyone been able to play (or test) it as a UCI or winboard chess engine yet? Thx AR :) :wink:

ps...Check shows no actual engine releases yet..... 8-) :wink:

https://www.google.com/url?esrc=s&q=&rc ... swFXl7FQKg


https://nanochess.org/chess4.html


https://www.google.com/url?esrc=s&q=&rc ... gMCyjwtcHG
zamfofex
Posts: 26
Joined: Wed Feb 16, 2022 6:21 am
Full name: P. M. Zamboni

Re: new(‐ish) engine in JavaScript (Deno) + APIs

Post by zamfofex »

supersharp77 wrote: Tue Mar 22, 2022 10:16 pm Well...haven't looked at your Github page yet..has anyone been able to play (or test) it as a UCI or winboard chess engine yet? Thx AR :) :wink:
There is a link in the readme to a UCI implementation for Dummyette. I was able to run it on GNOME Chess, and it seemed to work well!
supersharp77 wrote: Tue Mar 22, 2022 10:16 pm ps...Check shows no actual engine releases yet..... 8-) :wink:
I’m not sure about what this means, but if you mean that you want a release, there are none. It isn’t versioned, so it follows a “rolling release” model. You can always just clone the repository, or just run Deno on the GitHub URLs directly.

I once experimented with compiling it using qjsc from the QuickJS project, and although it worked, it was really slow, so I ended up never publishing that.

The easiest way to try it out is to clone this Gist: https://gist.github.com/zamfofex/d478de ... 5367b9bfdd, clone the Dummyette repo inside that directory, start an HTTP server (e.g. python3 -m http.server) and then finally open the local URL in your browser.

Code: Select all

git clone https://gist.github.com/zamfofex/d478de89883e1629ce21de5367b9bfdd dummyette-browser
cd dummyette-browser
git clone https://github.com/zamfofex/dummyette
python3 -m http.server 8017
zamfofex
Posts: 26
Joined: Wed Feb 16, 2022 6:21 am
Full name: P. M. Zamboni

Re: new(‐ish) engine in JavaScript (Deno) + APIs

Post by zamfofex »

I wanted to say that Dummyette can now play chess 960 on Lichess, if anyone finds interest in that!

I will note that the ‘fast-chess.js’ module in the project still doesn’t handle castling in chess 960 exactly as it should. That can impair the bot’s reasoning for chess 960 when castling is involved, but it shouldn’t cause crashes, so I postponed resolving it.

I have disabled the ‘faster-chess.js’ module (which can be found in the readme) because it uses third‐part code (by Ellie Moore), and I’m not sure how well it handles chess 960, so I’m afraid of crashes.
zamfofex
Posts: 26
Joined: Wed Feb 16, 2022 6:21 am
Full name: P. M. Zamboni

Re: new(‐ish) engine in JavaScript (Deno) + APIs

Post by zamfofex »

Some notes since last time I posted on this thread:
  • I updated my bot to use bitboards and eventually removed the ‘fast-chess.js’ module altogether. (See: https://www.talkchess.com/forum3/postin ... =7&t=80336)
  • I reworked the opening book architecture (it now uses a fixed PGN opening book as opposed to a configurable Polyglot opening book). It is less complete but simpler, and requires less RAM (useful if you want to run the bot on a VPS with limited RAM).
  • I implemented alpha‐beta pruning.
  • I added a piece‐square table to it.
  • I implemented quiescence search.
Overall, the ELO gain was of around 200 (from 1150 to 1350) on Lichess. The three latter points were specially useful for the ELO gain compared to the other ones.

One of my friends (2100 on Lichess) tried to play my bot, and he estimates it is around 1700 and that it just has yet to play more rated games, however its rating seems to be plateauing now at around 1350.

I’d love to know what your thoughts about it might be! The bot can be played on Lichess. (No account needed!)

Also: I understand that the opening book and PST chosen are suboptimal, but I find that they are aesthetically pleasing (in source code form), which I also value. My bot is never going to be the best, so I feel like there isn’t a need for me to squeeze a few ELO points out of a better opening book and PST and sacrifice personal perceived elegance for it.