What are great engines to learn the concepts from?

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

lojic
Posts: 71
Joined: Thu Jan 28, 2021 9:50 pm
Full name: Brian Adkins

What are great engines to learn the concepts from?

Post by lojic »

H.G. mentioned "TSCP" in another thread, so I looked it up. The website states:
Tom Kerrigan’s Simple Chess Program (TSCP) is a small, open-source chess engine that I made in 1997. It’s a tutorial engine, i.e., it’s designed to teach people how chess engines work.
It looks interesting.

I've also enjoyed looking through the Wukong source - I absolutely love the background image on the Online Wukong site :) I also test my engine against its different levels since I can't play automated games yet. Thanks Code Monkey King!

Are there other open source engines that should be on a "must look at" list - specifically for learning the concepts, as opposed to learning optimization techniques?
User avatar
mvanthoor
Posts: 1784
Joined: Wed Jul 03, 2019 4:42 pm
Location: Netherlands
Full name: Marcel Vanthoor

Re: What are great engines to learn the concepts from?

Post by mvanthoor »

lojic wrote: Thu Feb 04, 2021 3:08 am Are there other open source engines that should be on a "must look at" list - specifically for learning the concepts, as opposed to learning optimization techniques?
There are some:

Wukong and BBC by Maksim (CMK)
VICE by Richard Allbert (Bluefever Software)
The Javascript version fo VICE, also by Richard Allbert

Those are all covered by extensive video tutorials. I have watched all of them. (When CMK started doing his video tutorials, my engine was already 3/4th done, but I still got some stuff from them, because they explain some things just a bit differently. And I still need to watch his Texel Tuning video. I just hope that it's so good that I don't need anything else :p)

And, if I may say so, myself... my own engine Rustic.

It's heavily commented (about 35% of the source is comments). The comments don't explain WHAT the code is doing, because you can see that (hopefully, I try...) by reading the code itself; the comments explain WHY it is being done. It is also going to be accompanied by extensive documentation, which will basically be an extended version of the comments in the code.

It is also quite strong and fast (35-45 million leaves/sec in perft, and 3-5+ million nps when searching, on an i7-6700K) for an engine in this stage of development. It just got tested by CCRL, and it scored a rating of just a smidge under 1700. It is stronger than many engines that sport a much bigger feature list.

One of the advantages of my engine at this point is that it doesn't yet contain any highly advanced stuff. If you download the repository and switch to the Alpha 1 branch, you'll have the most basic chess engine ever, that will still play a decent game. (But it *is* a magic bitboard engine, not mailbox.)
Author of Rustic, an engine written in Rust.
Releases | Code | Docs | Progress | CCRL
User avatar
maksimKorzh
Posts: 771
Joined: Sat Sep 08, 2018 5:37 pm
Location: Ukraine
Full name: Maksim Korzh

Re: What are great engines to learn the concepts from?

Post by maksimKorzh »

lojic wrote: Thu Feb 04, 2021 3:08 am H.G. mentioned "TSCP" in another thread, so I looked it up. The website states:
Tom Kerrigan’s Simple Chess Program (TSCP) is a small, open-source chess engine that I made in 1997. It’s a tutorial engine, i.e., it’s designed to teach people how chess engines work.
It looks interesting.

I've also enjoyed looking through the Wukong source - I absolutely love the background image on the Online Wukong site :) I also test my engine against its different levels since I can't play automated games yet. Thanks Code Monkey King!

Are there other open source engines that should be on a "must look at" list - specifically for learning the concepts, as opposed to learning optimization techniques?
Thank you for your nice feedback!
Have a look at my recent Chinese chess engine - background image loos even more organic there) and also it plays around as strong as wukongjs - probably eval is a bit worse though.

Instead of mentioning specific engines I would rather try to deliver the general concept: there are many engines but there are only a few 'families':
micromax family (by HGM):
Sunfish (python)
My nibble chess (very obfuscated, not didactic)

TSCP family
Here it's hard to name the particular name but really lots of engines reusing say move stack implementation or collecting pv.

Fruit family
For those purists who love best practices in development like asserts and trying to do something serious and for a long time. Fruit is more often derived in coding style perspective rather than content.

Vice family
Biggest family IMO) while Vice it self is a kind of hybrid of TSCP and Fruit - it's like if TSCP was written in style of fruit

My wukong/bbc engines are simplified and purified Vice with extra didacticness - nothing original from code's content perspective but really very easy to understand code.


To answer your question - I would say Vice is fundamental - it's relatively simple on the one hand but shows the appoach to advanced techniques as well. I've been researching it's code for years and still looking at it. I just couldn't understand other engine's code for a long time.

For picking up basic search techniques I love CPW engine - a trully didactic resource - it follows Crafty's style but way more simple.

For evaluation probably Fruit is must see one - it introduced all the modern de-facto standards of handcrafted eval.
User avatar
hgm
Posts: 27790
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: What are great engines to learn the concepts from?

Post by hgm »

Fruit has a very clean coding style, and has a quite elaborate evaluation. And it is a mailbox engine. I can really recommend it.
User avatar
xr_a_y
Posts: 1871
Joined: Sat Nov 25, 2017 2:28 pm
Location: France

Re: What are great engines to learn the concepts from?

Post by xr_a_y »

Xiphos search is crystal clear I think.
Ethereal of course is well commented.
Dumb is very simple and instructive.
lojic
Posts: 71
Joined: Thu Jan 28, 2021 9:50 pm
Full name: Brian Adkins

Re: What are great engines to learn the concepts from?

Post by lojic »

hgm wrote: Thu Feb 04, 2021 9:08 am Fruit has a very clean coding style, and has a quite elaborate evaluation. And it is a mailbox engine. I can really recommend it.
I remember hearing about Fruit many years ago when I only played chess and didn't program chess. I'm surprised to hear it's a mailbox engine - I'll definitely check it out.
User avatar
hgm
Posts: 27790
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: What are great engines to learn the concepts from?

Post by hgm »

It is from the time 64-bit PCs were not invented yet. Bitboards are a lot slower when they do not fit in a single machine word. IMO bitboards are not so fast anyway.
Joost Buijs
Posts: 1563
Joined: Thu Jul 16, 2009 10:47 am
Location: Almere, The Netherlands

Re: What are great engines to learn the concepts from?

Post by Joost Buijs »

hgm wrote: Thu Feb 04, 2021 7:01 pm It is from the time 64-bit PCs were not invented yet. Bitboards are a lot slower when they do not fit in a single machine word. IMO bitboards are not so fast anyway.
This is not true. I already had a dual Opteron 64 bit PC back in 2003 and Fruit stems from a later date.

Maybe bitboards are not so fast, when coded right they are faster than a mailbox representation, especially for evaluation purposes. IMHO bitboards are the way to go if you really want to write a serious engine these days.
User avatar
mvanthoor
Posts: 1784
Joined: Wed Jul 03, 2019 4:42 pm
Location: Netherlands
Full name: Marcel Vanthoor

Re: What are great engines to learn the concepts from?

Post by mvanthoor »

Joost Buijs wrote: Fri Feb 05, 2021 8:09 am Maybe bitboards are not so fast, when coded right they are faster than a mailbox representation, especially for evaluation purposes. IMHO bitboards are the way to go if you really want to write a serious engine these days.
Even though bitboards are harder to implement (and with regard to magic bitboards, harder to wrap your head around), they really prove their return when you need to check stuff on the board. For example, the square_attacked() function needs to loop over the rays of the rook and the bishop, to find rooks, bishops and the queen, and then has to check against the other king, knights, and pawns. This is a seriously expensive operating. When using bitboards, this function boils down to one (massive) OR-statement.

The same goes for the evaluation. Really easy to find open lines, for example. You just need 8 masks (one for each open line) which you super-impose on the current board state, and there you have it. No looping along the lines. And so on...

After you've written the initial bitboard move generator, everything else becomes SO much easier, IMHO.

But, HGM is right at one thing: to run a bitboard engine efficiently, you _need_ a 64-bit computer and a 64-bit engine. When I compile my engine as 32-bit, the speed is half that of the 64-bit version. I can imagine that a 32-bit mailbox engine can be faster than a 32-bit bitboard engine, if the mailbox engine uses many incremental techniques to save on calculation.
Author of Rustic, an engine written in Rust.
Releases | Code | Docs | Progress | CCRL
Joost Buijs
Posts: 1563
Joined: Thu Jul 16, 2009 10:47 am
Location: Almere, The Netherlands

Re: What are great engines to learn the concepts from?

Post by Joost Buijs »

mvanthoor wrote: Fri Feb 05, 2021 8:37 am But, HGM is right at one thing: to run a bitboard engine efficiently, you _need_ a 64-bit computer and a 64-bit engine. When I compile my engine as 32-bit, the speed is half that of the 64-bit version. I can imagine that a 32-bit mailbox engine can be faster than a 32-bit bitboard engine, if the mailbox engine uses many incremental techniques to save on calculation.
It could be, but 32-bit engines and 32-bit computers are a relic of a very distant past.