St-Brieuc chess club

St-Brieuc chess club

Chess for all in Saint-Brieuc

Computer

Draw distance in chess openings

The draw distance in the minimum number of moves in a 1/2-1/2 chess game where StockFish evaluates the position with the “+0.00” score for the very first time.

Chess engines such as StockFish vs Leela chess draw games with a rate of 80%. Sorting these draw games according to the draw distance could help the human player to choose and learn openings until the quiet position of draw.

Have a look to the Scid vs PC database of StockFish vs Leela chess in the superfinal 14 of TCEC 2019 chapters “Draw distance by Stockfish with the Blacks” then “… with the Whites”. Hereafter enclosed is a short extract:

Mov B Nbr ECO    Draw in #Mov moves by Stockfish 190203 with the (B)lacks in game #Nbr
007 B 061 A40g    Queen’s pawn Keres defence 1.d4 b6 2.c4 e6 3.e4
007 B 097 A43n    Old Benoni defence 1.d4 c5 2.d5 Nf6 3.Nf3 b5
008 B 015 B06p    Robatsch (modern) defence 1.e4 g6 2.d4 Bg7 3.Nc3 d6 4.Be3 a6
…
125 B 079 B42o    Sicilian Kan, 5.Bd3 1.e4 c5 2.Nf3 e6 3.d4 cxd4 4.Nxd4 a6 5.Bd3 Nf6 6.O-O Qc7 7.Qe2 d6 8.c4
130 B 075 C93    Ruy Lopez closed, Smyslov defence 1.e4 e5 2.Nf3 Nc6 3.Bb5 a6 4.Ba4 Nf6 5.O-O Be7 6.Re1 b5 7.Bb3 O-O
164 B 039 C33    KGA bishop’s gambit, Maurian defence 1.e4 e5 2.f4 exf4 3.Bc4 Nc6

It means that StockFish needs 164 moves to draw with the Blacks in the
KGA bishop’s gambit, Maurian defence. Whites should use another opening that the KGA bishop’s gambit if they wish to win.

Let us write the PowerShell parser in order to generate these statistics.

The main input file is the PGN generated by the pgnTcec2Scid.ps1 parser in the Scid format. We need two other files:

  • the Scid ECO with a 4th letter thanks to ecoList.txt
  • a short introduction to the associated opening in ScidOpening.txt

Step-by-step instructions:

  1. Download the TCEC 2019 superfinal to Scid vs PC STOCKFISH vs Leela database. Unzip it.
  2. Open Tcec2019SuperFinal14.si4 in Scid vs PC
  3. Menu “Help” > “Startup window”
  4. Above the option [ ] “Keep open after startup”, there is a large empty input box in which you can enter the Scid command:
sc_game list 1 100 f*.o*_r1\n ecoList.txt

According to the folder where is installed Scid vs PC, this Scid command generates the text file ecoList.txt in C:\Chess\Scid\Prog\bin:

1.D32f_=
2.D32f_=
3.B80e_=
4.B80e_=
...
99.B99x_=
100.B99v_=

Consult the C++ comment in C:\Chess\Scid\Source\scid_vs_pc-4.19\src\index.cpp

// IndexEntry::PrintGameInfo():
...
//          f:  Game number
//          o:  ECO code.
//          r:  Result. Prints as 1 byte (1/0/=*)

We add a simple delimiter of one character such as “.” after the Game number and “_” between ECO and result in order to simplify the parser.

Enter the following Scid command in the Startup window to get the first moves of a given opening by ECO code:

foreach eco {D32f B80e} {::splash::add [sc_eco summary $eco htext:false]}

This loop for two ECO codes in Scid syntax generates:

D32f [QGD Tarrasch: von Hennig-Schara Gambit, 5.Qa4+]  1.d4 d5 2.c4 e6 3.Nc3 c5 4.cxd5 cxd4 5.Qa4+ 
D32f [QGD Tarrasch: von Hennig-Schara Gambit, 7.Qxd5 Nc6]  1.d4 d5 2.c4 e6 3.Nc3 c5 4.cxd5 cxd4 5.Qa4+ Bd7 6.Qxd4 exd5 7.Qxd5 Nc6 

B80e [Sicilian: Scheveningen, 6.Be3 a6]  1.e4 c5 2.Nf3 d6 3.d4 cxd4 4.Nxd4 Nf6 5.Nc3 e6 6.Be3 a6 

The list has been manually simplified in NotePad++ when a given ECO generates more than one openings. So there are 100 lines, one by game in the match of the TCEC superfinal.

In Windows PowerShell ISE, the output window shows:

PS C:\Users\Chess> C:\Users\Chess\Documents\Powershell\pgnDrawDist.ps1
Mov C Nbr ECO	Win in #Mov by Stockfish 190203 in game #Nbr

044 W 016 B06p	Robatsch (modern) defence 1.e4 g6 2.d4 Bg7 3.Nc3 d6 4.Be3 a6
049 B 021 A22	English Bellon gambit 1.c4 e5 2.Nc3 Nf6 3.Nf3 e4 4.Ng5 b5
051 W 022 A22	English Bellon gambit 1.c4 e5 2.Nc3 Nf6 3.Nf3 e4 4.Ng5 b5
052 B 007 C34	KGA Schallop defence 1.e4 e5 2.f4 exf4 3.Nf3 Nf6
...

Mov C Nbr ECO	Loss in #Mov by Stockfish 190203 in game #Nbr

041 B 063 C12h	French MacCutcheon, Janowski variation 1.e4 e6 2.d4 d5 3.Nc3 Nf6 4.Bg5 Bb4 5.e5 h6 6.Be3
...

Mov B Nbr ECO	Draw in #Mov by Stockfish 190203 with the (B)lacks in game #Nbr

007 B 061 A40g	Queen's pawn Keres defence 1.d4 b6 2.c4 e6 3.e4
007 B 097 A43n	Old Benoni defence 1.d4 c5 2.d5 Nf6 3.Nf3 b5
...

Mov W Nbr ECO	Draw in #Mov by Stockfish 190203 with the (W)hites in game #Nbr

009 W 082 D15y	QGD Slav Tolush-Geller gambit 1.d4 d5 2.c4 c6 3.Nf3 Nf6 4.Nc3 dxc4 5.e4 b5 6.e5 Nd5 7.a4 e6
012 W 044 B89	Sicilian Velimirovic attack 1.e4 c5 2.Nf3 d6 3.d4 cxd4 4.Nxd4 Nf6 5.Nc3 e6 6.Bc4 Nc6 7.Be3 Be7 8.Qe2 O-O 9.O-O-O Qc7 10.Bb3 a6

Download “Draw distance PowerShell parser”

DrawDistance.zip – Downloaded 758 times – 1.00 MB