Latest Updates:
Normal Topic Practice your opening against an engine (Read 205 times)
FreeRepublic
God Member
*****
Offline


I Love ChessPublishing!

Posts: 773
Location: Georgia
Joined: 06/08/17
Gender: Male
Re: Practice your opening against an engine
Reply #1 - 05/31/24 at 00:21:52
Post Tools
Very impressive! I'm no computer geek, so I cannot appreciate your work fully. I enjoyed importing the PGN into COW and using their training feature.

I have Dearing's Play the Nimzo-Indian (Adobe Digital Edition).
  
Back to top
 
IP Logged
 
an ordinary chessplayer
God Member
*****
Offline


I used to be not bad.

Posts: 1690
Location: Columbus, OH (USA)
Joined: 01/02/15
Practice your opening against an engine
05/29/24 at 16:44:32
Post Tools
You want to practice the Nimzo-Indian with black against the engine, but it plays 1.Nf3. Or 1.e4. Or 1.d4 but not 2.c4. How to do it? There is a way, using the polyglot program. Here is the basic idea:
  1. Use the polyglot executable to make a custom .bin book for the opening you want to practice.
  2. If your engine supports polyglot books, use your favorite GUI to tell the engine to use your book. 
    Otherwise, use the polyglot executable again, this time to make the moves from the book. 
    Either way works, and I will show both.

Read about polyglot here: https://wbec-ridderkerk.nl/html/details1/PolyGlot.html . Everything I'm doing here is in the polyglot readme. (Actually the readme at wbec-ridderkerk has some issues. I used the one in the fruit 2.1 .zip file.) There are some newer versions of polyglot out there that have book learning or other features added, but for our purposes version 1.4 or later is good enough. I'm using linux, but polyglot works equally well on Windows and Mac, although the paths will be different. I assume you already have a working engine. Onward.

As a Nimzo-Indian base, I used Edward Dearing (2005) Play the Nimzo-Indian. I looked up his 50 numbered games in the ChessBase Big Database, and saved them in a pgn file. Chapter 9 (4.Nf3 O-O) is a little different, no numbered games there, but I looked up 9 of the game references and added those as well. Then in preparation for making the book, I changed the games like so:
  • A few games Dearing suggested an improvement for black. In each case I made that move the main line and put the actual game continuation in a comment. I didn't copy any of his further analysis, but for a real repertoire you would carry the improved lines to the end. 
  • His Game 10 (a loss for black) was for illustrative purposes, and he recommends a different line in Game 11. I put Game 10 as a comment to Game 11 so it wouldn't be added to the book.
  • I changed all the game results to 1/2-1/2. Polyglot weights the book by frequency and result. Making all the results the same forces polyglot to only use the frequency. Why do we care? There were 39 black wins out of 59 games (58 not counting Game 10), and we want the engine to play all the lines for white, not just the ones where white won or drew.
  • I fixed some of the early move orders to match his index. For example 1.d4 e6 2.c4 Bb4+ 3.Nc3 Nf6 I changed to 1.d4 Nf6 2.c4 e6 3.Nc3 Bb4. This is a little fussy, but in some openings it matters a great deal.

I attached the resulting .pgn file here on chesspub.

Polyglot is a command line program. Below is the command to create a book, using all the games ,with up to 20 moves, with moves for both sides. (We could use -only-black or -only-white to create a book for just one side, which is kind of special but I won't get into it right now.)
Code
Select All
$ polyglot make-book -min-game 1 -max-ply 40 \
> -pgn Dearing-2005-v2.pgn -bin Dearing-2005-v2-both.bin
PolyGlot 2.0.4 by Fabien Letouzey.
inserting games ...
59 games.
1550 entries.
filtering entries ...
1550 entries.
sorting entries ...
saving entries ...
all done!
$

// no idea why it says 59 games there, should be 58 ... 


Let's open our book in Scid and see what it looks like. I copied the book to Scid's books directory, on my system it's ~/scid_5_0_2/share/scid/books/ . Then on the Scid menu I click Windows | Book Window and select my book in the dropdown. When the Board shows the initial position, the book says "d4 100%". An engine playing white and using this book will always move 1.d4! After making the first three moves of the Nimzo-Indian, the book says:

Qc2        28%
e3         28%
Nf3        16%
Bg5        7%
a3         7%
f3         5%
g3         5%
Qb3        3%
Bd2        2%

Time to play a game. The fruit engine is by the same author as polyglot, so unsurprisingly it's compatible with polyglot books.
  • I copied the book again, this time into fruit's directory, on my system it's /usr/games/fruit21/. 
  • On the Scid menu click Tools | Configure Engines which opens the Analysis Engine... window.
  • Click the New... button. Fill in Name = fruit , Command = /usr/games/fruit21/fruit 
  • Click OK a couple times. 
  • Flip the board so black is on the bottom, either by clicking on the board menu and choosing Rotate, or by typing a period on the keyboard. 
  • On the Scid menu click Play | Serious Game which opens the Game Configuration window.
  • Select fruit as the engine, see that Specific opening is NOT enabled, see that Use book IS enabled, and in the dropdown under that select our new book ( Dearing-2005-v2-both.bin ).
  • Click Play

After a brief pause for startup, the engine plays 1.d4! As long as you stay in book by replying with Dearing's repertoire move, the engine will move quickly. Once you leave book, the engine will have to think before moving. You can cheat if you want, just open the Book Window and Scid will show you the moves for both sides as you play. Were you hoping for spaced repetition? Sorry, you will have to keep those statistics yourself. Save the game(s) afterwards and compare to your book.

Now for using polyglot as an engine adapter. Polyglot accepts WB protocol commands from the GUI and sends UCI protocol commands to the engine, so we will test it in xboard (on Windows you would use Winboard.exe, it's functionally the same). If you don't have xboard or Winboard, you can use another GUI as long as it accepts WB engines. For example, Arena.

To make this work, we just need a polyglot .ini file that (a) points to the engine; (b) points to the polyglot book; (c) tells polyglot to use the book; (d) enables or disables the engine's OwnBook (if it has one) entirely at your discretion.
Code
Select All
$ ls /usr/games/critter16a
book.cbk  critter  critter-16a-64bit
$ /usr/games/critter16a/critter
Critter v1.6a 64-bit, by Richard Vida
hardware POPCNT enabled
uci
id name Critter 1.6a 64-bit
id author Richard Vida
option name Hash type spin default 64 min 8 max 8192
option name Ponder type check default false
option name OwnBook type check default true
option name Book File type string default book.cbk
  etc. etc.
uciok
quit
$ sudo nano /usr/games/critter16a/dearing.ini
[sudo] password for user_xyz:
$ cat /usr/games/critter16a/dearing.ini
[PolyGlot]
EngineName = critter-dearing
EngineDir = /usr/games/critter16a
EngineCommand = ./critter
Log = false
LogFile = /tmp/critter-dearing.log
Book = true
BookFile = /usr/games/fruit21/Dearing-2005-v2-both.bin

[Engine]
OwnBook = false

$ whereis polyglot
polyglot: /usr/games/polyglot /usr/share/man/man6/polyglot.6.gz
$  


First I checked the engine to make sure it supports the OwnBook parameter. Then we created the .ini file. I re-used the book from the fruit directory; or I could have re-used the one from Scid's books directory; or I could have made yet another copy in the critter directory.

On the xboard (or Winboard) menu
  • Click Engine | Edit Engine List... to open the Registered Engines window.
  • At the bottom, type a new line like so:
    "critter-dearing" -fd "/usr/games/critter16a" -fcp "polyglot dearing.ini"
  • Click commit changes
  • Click OK.

So xboard thinks the "first chess program" is polyglot, but behind the scenes polyglot looks for dearing.ini in the "first directory" critter16a/ , then dearing.ini tells polyglot to call critter. And how does the book work? Well, if polyglot can get a move from the polyglot book, it won't ask critter to think, it will just return the book move. Only if polyglot is out of book will it ask for a move from critter. Critter might also have a book, but we disabled it in dearing.ini . 

Back to xboard.
  • Click Engine | Load New 1st Engine... to open the Load first engine window.
  • On the left hand side, select critter-dearing which we just added.
  • Click OK.
  • Click File | New Game
  • Click Mode | Analysis Mode to open the Engine output window. It should say critter-dearing at the top.
  • Click Mode | Edit Game to stop the engine
  • Close the Engine output window
  • Click View | Flip View to put black at the bottom
  • Click Mode | Machine White

The engine plays 1.d4! instantly. And if you reply 1...Nf6, it plays 2.c4! instantly. And so on.
  

Dearing-2005-v2.pgn ( 40 KB | 15 Downloads )
Back to top
 
IP Logged
 
Bookmarks: del.icio.us Digg Facebook Google Google+ Linked in reddit StumbleUpon Twitter Yahoo