Building a strong Julia chess engine

Should we build a strong chess engine? How do I go about it? I need to get started by interfacing with UCI, but how? Then, what next? Any idea to leverage Julia’s strength? For example, I’m thinking of generating code using Julia’s metaprogramming to generate some parts of the engine.

5 Likes

I know that one. Thanks for the suggestion. That was a utility package for representing boards and so on, and the board representation here could be useful, but this was not specifically for building a UCI chess engine or something. Most chess engines have their own board representation and move generation. This package contains utility for using other engines, but not necessarily for building one.

There’s also GitHub - abahm/Chess.jl: Chess engine written in Julia

Perhaps tell us what you’ve already found :joy::joy::joy:

I found that one too. Nice one. This unlicensed, unnamed chess engine, IDK the strength, but the last commit was 2 years ago.

well, some good opening gambits for both packages would be doing some tests, issues, and pull requests to get them up to current Julia status. Or, if you don’t see any activity, contemplate a (repo, not knight) fork!

3 Likes

My Chess.jl package is, as @Tarny_GG_Channie points out, not really that well suited for writing a chess engine (although you certainly could). It’s designed more for higher level-chess software. Some low-level parts of the code (like the SquareSet type) would probably be useful, but I wouldn’t recommend using higher-level stuff like the Board type.

On the other hand, as some of you probably know, I also have some not insignificant experience writing chess engines, and I’ve been thinking about writing a Julia language engine at some point. I’ve even been toying with the idea of writing a book using chess engine development as a vehicle for teaching Julia and Flux, but it’s unlikely to ever happen (I doubt there would be any significant market for such a book).

Anyway, even if a book is unrealistic, I would certainly be willing to help getting a strong Julia chess engine up and running, if the community thinks such a project would be of interest.

3 Likes

Disclaimer, I don’t know very much about chess programming but I have significant experience with (game of) go programming, which at a higher level should be similar enough.

A word of advice is to only embark on such a project if you enjoy playing chess or enjoy coding/inventing algorithms needed for a chess engine, preferably both.

I need to get started by interfacing with UCI, but how?

The interfacing part is never particularly difficult. Find the specification and implement it, unless there’s already something out there you can use. Presumably API Reference · Chess.jl might be helpful.

Any idea to leverage Julia’s strength?

Game programming is much more about algorithms than languages. I would say that Julia has the right features to be very productive for the purpose but there’s nothing magical about it.

I’m thinking of generating code using Julia’s metaprogramming to generate some parts of the engine.

Unless you have specific ideas how to use this to your advantage, metaprogramming isn’t something I would consider at an early stage.

2 Likes

Unless you have specific ideas how to use this to your advantage, metaprogramming isn’t something I would consider at an early stage.

I agree. Contrary to what most people believe, chess engines are quite small and simple programs, and metaprogramming doesn’t add a lot of benefits (apart from being fun).

One particular use of metaprogramming I was thinking was searching for patch that gains elo, my idea was that there would be a huge search tree searched with lots of nodes (Using long time), then compute which node was actually searched with each patch. Then, we can search for variants of the engine that searches the right branch.

Just to know, are you considering a “classical” chess engine or a Reinforcement Learning based one? In such case the first step would be likely look for a sponsor for the computational costs :slight_smile: :slight_smile:

Modern chess engines normally use a small, special neural network.

The issue isn’t using the neural network, it is the compute for training the weights of such a network.

Training an NNUE style network isn’t an issue, a single reasonably fast computer would be easily enough. Generating the training data (normally done by playing a lot of self-play games) takes far more computing time, unless you take the shortcut of using somebody else’s data. But you will have to play a massive number of test games anyway.

Developing a top engine does take a lot of computing resources, but it’s not really about training a neural network. It’s mostly just the expense of running thousands or tens of thousands of test games to test whether every little change you do to the code is an improvement. In the early phases of development, when improvements are easy to find and each improvement results in a giant leap in performance, testing is cheap. As the engine gets stronger, improvements are rarely worth more than a single digit number of rating points, and testing becomes very computationally intensive.

2 Likes

Ah, that makes sense! Thanks for the clarification.