Chess engine in Zig

Hello,
Just ported my C++ chess engine to Zig !

C++: GitHub - ppipelin/radiance_archived: UCI Chess Engine written in C++
Zig : GitHub - ppipelin/radiance: UCI Chess Engine written in Zig

Really enjoyed the ride which went smoothly.

I definitely enjoyed a lot of zig features counting :

  • The build system with its language and cross compilation.
  • The test system
  • The std library which had all the features I needed (like hash maps)
  • The struct system with its function
  • The packed struct

A big shoutout to Avalanche chess engine which showed clever use of enums which where so useful to me.

I was happy to drop a complex OOP to a more functional approach. OOP had its advantages for sure but in a fast-paced program such as a chess engine, it is not that much suited (e.g. Stockfish mostly uses namespaces).

FYI the move generation is around 8Mnps

Feel free to contribute !

EDIT : I forgot to mention it is playable on Lichess if you want to try ! RadianceEngine : Activity • lichess.org and you can watch its games on the dedicated TV.

13 Likes

A wonderful project which i am using to study Zig! BTW, what level can it achieve comparing to Alpha Zero which uses Deep Learning & Neutral Network ?

Regards !

2 Likes

Glad to hear but be careful about my code, I started Zig this year, with this project so there might be wrong parts.

AlphaZero is closed source but a similar engine is LeelaZero which would win 1000 games to 0 I’d say haha.

Writing the evaluation by hand can be tricky and i have to test not to insert regressions, so a non-supervised learning like NNUE system would be nice. I think I will add it one day, it has a high priority to me.

Some people are testing engines and prior versions of radiance were ranked 724/783
https://computerchess.org.uk/ccrl/404/

I’d say its FIDE elo would be around 2000, a good chess player.

I forgot to mention its playable (without account) on lichess ! I’m editing the first post with the link.

3 Likes

cc @jcalabro (he works at chess.com)

2 Likes

Actually he works at bluesky now.

Cool! Did you compare performance to your old project?

Very cool! I see you do have a legal move generator. Not this pseudo-legal move nonsense? I while ago I discovered that the overall performance is better if you do it smartly. And from what I saw I think you do.

For speed comparision, I had a great increase during move generation but had differences in the code.
→ In my c++ version, every pseudo legal move had to be tested to be legal separately, whereas now I have attacked squares and pins taken into account during move generation via bitboards.

I went from 2.3Mnps to 7.5Mnps. And in both cases I use precomputed dictionnaries instead of magic number hashing.

Exactly. I found out that during move the generation procedure testing for legal is faster than doing it afterwards.
I will try and check out your code.
Interested in these precomputed dictionaries. No magics?
Is that speed you mention for perft or the thinking engine?

The dictonnaries is the first step before magics. Magics just compresses the keys so that it fits into arrays but data is the same.

As for the speed mentionned earlier, it’s perft (so no evaluation nor alpha beta pruning), in game I’m closer to 1.5Mnps at startpos (previously 300knps).

1 Like

Played against your radiance bot on a 5g Motorola phone and got my butt kicked! Well done bro

2 Likes