How to write 2200+ elo chess engine within 500 to 1000 lines of code with pure evaluation(No NNUE or EGTB)?

Discussion of chess software programming and technical issues.

Moderator: Ras

dangi12012
Posts: 1062
Joined: Tue Apr 28, 2020 10:03 pm
Full name: Daniel Infuehr

Re: How to write 2200+ elo chess engine within 500 to 1000 lines of code with pure evaluation(No NNUE or EGTB)?

Post by dangi12012 »

OliverBr wrote: Sat Nov 20, 2021 9:11 pm
shahil4242 wrote: Sat Nov 20, 2021 5:10 am
OliverBr wrote: Thu Nov 18, 2021 11:40 pm
abulmo2 wrote: Wed Nov 17, 2021 2:01 pm You may have a look at dumb, it is about 1200 lines of code and 2677 Elo at CCRL 40/4.
You can also give a look at OliThink which is very strong (2867 Elo for version 5.9.7 on CCRL 40/4) with a very compact source code (1033 lines of code for version 5.10.1).
Actually dumb is really intriguing. It's very compact and well written.
I think one of the version of OliThink had uses rotated bitboard.What is the result of perft? Does it is faster than magic bitboard?is it is woth learning about rotated bitboard.
Yes. OliThink4 (https://github.com/olithink/olithink4)
had rotated bitboards. And it had good results and caught the attention of many chess pioneers. One of them them is a Stockfish developer.

The Kindergarten bitboards of OliThink5 (https://github.com/olithink/OliThink)
was another independent development of my own without looking into other sources. I got the name many years after its creation.

The perft of OliThink5 (https://github.com/olithink/OliThink/tree/oliperft)
is better than OliThink4.
But this is still no decisive argument which to use, because the move generation is supposed to be compatable with the rest of the programm.
I know that you are leaving a lot of performance on the table by using C.
If you were to use C++ all your macros should be replaced by constexpr / consteval functions and you get access to more modern compiler backends.
Also compilers can do more to optimize int& paramters vs int* parameters. So the very core of poplsb is surely not optimal in C vs C++.
Just start by replacing (int c) with template<int c> and your code will speedup by more than 2x.

Code: Select all

#define PCA3(x, c) (pcaps[c][(x) | 64] & (P.color[c^1] | (BIT[ENPASS] & (c ? 0xFF0000 : 0xFF0000000000))))
I can promise you that because 1 year ago my pet project had just that switch.
All "ifs" magically disappear. Most array lookups go away. Color becomes a compiletime variable - and most importantly: The code becomes much shorter and cleaner to read and maintain.
Worlds-fastest-Bitboard-Chess-Movegenerator
Daniel Inführ - Software Developer
dangi12012
Posts: 1062
Joined: Tue Apr 28, 2020 10:03 pm
Full name: Daniel Infuehr

Re: How to write 2200+ elo chess engine within 500 to 1000 lines of code with pure evaluation(No NNUE or EGTB)?

Post by dangi12012 »

shahil4242 wrote: Wed Nov 17, 2021 6:58 am
Here would be another excellent source to look up clean code:
https://jim.sh/svn/jim/vendor/microwind ... /tuxchess/
Worlds-fastest-Bitboard-Chess-Movegenerator
Daniel Inführ - Software Developer