Step 2: Compiling the Stockfish Chess Engine



The Best Chess Engine In The World Is Free

For a number of years, Stockfish has been the strongest chess engine.  Lc0, or "Leela" has consistently come in second place.
picture courtesy of https://tcec-chess.com/

Stockfish has a number of strong structural advantages relative to other chess engines:
  • It has a well defined, public development process with a large community of people who contribute improvements and/or testing capacity. Anyone can submit code changes to be tested to see if they improve performance. Testing is done on one platform that is open to all and is clearly visible to all participants, with well defined criteria for accepting/rejecting contributions. We'll talk about this more in another post, but Lc0's development process is much more opaque and segmented.
  • Ideas that improve performance are quickly incorporated in the "official" development version of Stockfish which is easily obtainable from one source. Again, not so with Lc0.
  • Stockfish is a CPU based engine and strong CPUs have been cheaper/easier to obtain than Graphical Processor Units that Lc0 relies on.  A strong 32-thread CPU like the AMD 7950x is only $600 MSRP compared to a Nvidia 3090 GPU which is difficult to find for less than $1,000 at the present time.

Set Up The Fastest Stockfish For Your Computer Architecture

In a terminal positioned in the directory of your choice, simply type:
git clone https://github.com/official-stockfish/Stockfish.git

and then run the bash script below (i.e., chmod +x makeFish.sh && ./makeFish.sh)

Your executable with be in the /Stockfish/src directory.  

There are two common compilers used to compile Stockfish: gcc and clang.  In the makeFish.sh script, we default to the gcc version.  But on some computers the clang version will run more quickly.  To test this for your computer, you can 1) copy your stockfish executable to "stockfishGCC" and re-run makeFish.sh after commenting out line 131 to make stockfish with gcc and uncomment line 132 to make it with clang.  Then to see which version runs faster on your machine, you cd into the /Stockfish/src directory and run bench_parallel.sh using the command:

./bench_parallel.sh ./stockfish ./stockfishGCC 20 10

The bench_parllel.sh script will put both versions through 10 iterations of some position analyses to depth 20 and compare their relative speed.  For some architectures, one version will be superior to the other.  But, as the example below illustrates, you may also find large error bars and inconsistent results suggesting the two versions are pretty similar. 


Congratualtions! At this point you have the most up to date version of the world's strongest chess engine compiled to run as fast as it can on your computer.  If you periodically "cd" into your Stockfish directory and type "git pull", you can keep up with the latest developments in the engine (if there are changes, simply re-run makeFish.sh from the directory one level above). 

You can also subscribe to get email notifications of changes in Stockfish by creating a github account and following the stockfish github account.  And there is an active community of contributors and users on the Stockfish Discord channel.

In the next blog post, we will talk about making the Syzygy endgame table-base available to your Stockfish engine.

Comments

Popular Posts