Blogs

Ubuntu Linux and Chess -- Engine configuration

delatbabel
| 4

I'm now going to launch into a slightly technical discussion of chess engine configuration using scid.

Before I start, I'm reminded of an old saying -- Windows programmers say "it's broken, how do we fix it?", Unix programmers say "it's not broken, don't fix it" and system programmers say "let's break it, then we'll find out how it really works".

So one of the reasons I like to use Linux is it gives me a bit of an opportunity to tinker with things, and right now I'm going to do a bit of tinkering.

UCI engines have a bunch of configuration options that can be sent to them.  We've set up stockfish to use an opening book, but we saw on the UCI configuration engine that there were a few other options as well.  The question is, how does scid now how to configure an engine and what the options are?  And the answer is -- the engine tells it.

To illustrate this, start stockfish on the command line by starting a terminal window and typing this:

stockfish

Stockfish will respond with a few lines of text and then you should type:

uci

Now you'll see a pile of output that looks like this:

id name Stockfish 2.1.1 64bit
id author Tord Romstad, Marco Costalba and Joona Kiiski

option name Use Search Log type check default false
option name Search Log Filename type string default SearchLog.txt
option name Book File type string default book.bin
option name Best Book Move type check default false
option name Mobility (Middle Game) type spin default 100 min 0 max 200
option name Mobility (Endgame) type spin default 100 min 0 max 200
option name Passed Pawns (Middle Game) type spin default 100 min 0 max 200
option name Passed Pawns (Endgame) type spin default 100 min 0 max 200
option name Space type spin default 100 min 0 max 200
option name Aggressiveness type spin default 100 min 0 max 200
option name Cowardice type spin default 100 min 0 max 200
option name Minimum Split Depth type spin default 4 min 4 max 7
option name Maximum Number of Threads per Split Point type spin default 5 min 4 max 8
option name Threads type spin default 4 min 1 max 32
option name Use Sleeping Threads type check default false
option name Hash type spin default 32 min 4 max 8192
option name Clear Hash type button
option name Ponder type check default true
option name OwnBook type check default true
option name MultiPV type spin default 1 min 1 max 500
option name Skill Level type spin default 20 min 0 max 20
option name Emergency Move Horizon type spin default 40 min 0 max 50
option name Emergency Base Time type spin default 200 min 0 max 30000
option name Emergency Move Time type spin default 70 min 0 max 5000
option name Minimum Thinking Time type spin default 20 min 0 max 5000
option name UCI_Chess960 type check default false
option name UCI_AnalyseMode type check default false
uciok

That information is stockfish telling you what configuration settings it has, and what the options for the configuration are.  So, for example, it has an option called "Skill Level" which is of type "spin" which has a default of 20 and possible values from 0 to 20 as seen on this line:

option name Skill Level type spin default 20 min 0 max 20

Now, start a different engine, this time toga2, and ask for its settings:

toga2
uci

They look like this:

id name Toga II 1.4.1SE
id author Thomas Gaksch and Fabien Letouzey
option name Hash type spin default 16 min 4 max 1024
option name Search Time type spin default 0 min 0 max 3600
option name Search Depth type spin default 0 min 0 max 20
option name Ponder type check default false
option name OwnBook type check default true
option name BookFile type string default performance.bin
option name Bitbases Path type string default /usr/share/egbb/
option name Bitbases Cache Size type spin default 16 min 16 max 1024
option name MultiPV type spin default 1 min 1 max 10
option name NullMove Pruning type combo default Always var Always var Fail High var Never
option name NullMove Reduction type spin default 3 min 1 max 4
option name Verification Search type combo default Always var Always var Endgame var Never
option name Verification Reduction type spin default 5 min 1 max 6
option name History Pruning type check default true
option name History Threshold type spin default 70 min 0 max 100
option name Futility Pruning type check default true
option name Futility Margin type spin default 100 min 0 max 500
option name Extended Futility Margin type spin default 200 min 0 max 900
option name Delta Pruning type check default true
option name Delta Margin type spin default 50 min 0 max 500
option name Quiescence Check Plies type spin default 1 min 0 max 2
option name Material type spin default 100 min 0 max 400
option name Piece Activity type spin default 100 min 0 max 400
option name Piece Square Activity type spin default 100 min 0 max 400
option name King Safety type spin default 100 min 0 max 400
option name Pawn Structure type spin default 100 min 0 max 400
option name Passed Pawns type spin default 100 min 0 max 400
option name Toga Lazy Eval type check default true
option name Toga Lazy Eval Margin type spin default 200 min 0 max 900
option name Toga King Safety type check default false
option name Toga King Safety Margin type spin default 1700 min 500 max 3000
option name Toga Extended History Pruning type check default false                                                            
option name Number of Threads type spin default 1 min 1 max 16

These options are all quite different!

Now start scid, and choose Tools->Analysis Engine.  Start by selecting stockfish from the list, and click Edit.  In the next window click "Configure UCI engine" and you will see a window pop up with all of the stockfish configuration options.

These options will be named the same as the options you got from stockfish using the "uci" command.  Press the up and down arrows next to the Skill Level box and you will see that you can change it to any value between 0 and 20 -- this is what type "spin" means.  So, the scid programmers have used the information that was made available by the stockfish programmers to draw a window to allow you to tell scid how to configure stockfish.

Change the "Skill Level" setting in stockfish from the default value of 20 all the way down to 0.  Press Save and then OK in the next windows to go back to the main screen.  Now select Play -> Serious Game in the scid menu, and select stockfish from the engine list (you will also see a "Configure UCI engine" button there where you can confirm the settings you set up in analysis engine), and play the game.  You should find, unless you are a complete beginner, that you can beat stockfish at this level.

It takes a bit of digging through the stockfish documentation to figure out what's happened here, but essentially stockfish says, at various skill levels below 20, that it will not always pick the best move.  In fact at skill level 0 it often picks a complete blunder and so you should be able to beat it.

You can use this to practice your chess against the stockfish engine -- start at level 0 or 1 and work up from there until you find a level where stockfish gives you a challenge.  Then slowly increase the levels as you learn more about chess (follow the videos and tactics training on chess.com to improve your skill) and you should find yourself beating higher and higher levels over time. Of course if you can beat level 20 on a regular basis then you should probably be entering some tournaments to pick up those GM norms.

Other engines aren't quite so kind as stockfish when it comes to setting skill levels, but they do have many other configuration settings to play with, if you want to change the way they do their analysis.  There is plenty of room for experimentation here.