How to Very Quickly Add Engines to the Cutechess-cli List on Windows

Discussion of chess software programming and technical issues.

Moderator: Ras

User avatar
Brunetti
Posts: 404
Joined: Tue Dec 08, 2009 1:37 pm
Location: Milan, Italy
Full name: Alex Brunetti

How to Very Quickly Add Engines to the Cutechess-cli List on Windows

Post by Brunetti »


Step 1: Create a Batch File

Save the following content as a batch file in a stable location, such as the Cutechess folder:

Code: Select all

@echo off
setlocal enabledelayedexpansion
set "outputFile=C:\Chess\cutechess\engines.json"
set "fullname=%~1"
for %%I in ("%fullname%") do set "name=%%~nI"

for %%I in ("%fullname%") do (
    set "workingdir=%%~dpI"
    set "workingdir=!workingdir:\=\\!"
)
set "fullname=!fullname:\=\\!"
setlocal enabledelayedexpansion
(
    set header=0
    for /f "usebackq delims=" %%L in ("%outputFile%") do (
        if !header! EQU 2 (
	        echo %%L >> "%outputFile%.tmp"
	)
        if !header! EQU 1 (
            echo {"command":"%fullname%","name":"%name%","protocol":"uci","workingDirectory":"%workingdir%"}, >> "%outputFile%.tmp"
	    echo %%L >> "%outputFile%.tmp"
            set /a header=2
        )
        if !header! EQU 0 (
            echo [ >> "%outputFile%.tmp"
            set /a header=1
        )
    )
) && move /y "%outputFile%.tmp" "%outputFile%"
You must customize the third line by specifying the correct location of your engines.json file.
You can name the file as you like; for example, I named it engines_adder.bat.

Step 2: Add a Registry Key

Using the Windows Registry Editor (regedit), add a new key to the registry as shown in this image:

Image

(The language of your Windows version may differ, but the process remains the same.)
The command name is up to you; in this example, I used AddCuteEngine.

Step 3: Add Engines to engines.json via the Context Menu

Once the registry key is added, you'll find the new command AddCuteEngine (or the name you chose) in the context menu of Windows Explorer. This menu appears when you right-click on a file:

Image

Clicking on the context menu command will automatically add the selected engine to your engines.json file:

Image

Final Notes

The default protocol is UCI, so remember to edit the file if you are adding an XBoard engine. If needed, you can even create two separate commands for the two protocols.

For those using the Cutechess GUI, it may be more convenient to add engines directly through it. In my experience, this little utility is particularly handy for those who prefer to work directly within their folders.

Alex