Using the Universal Chess Interface

Using the Universal Chess Interface

Let's assume the GUI is facilitating a match between a human user and an engine. Let's say the user starts with e2e4. Then the commands would look something like:

// GUI: tell the engine to use the UCI protocol
uci

// ENGINE: identify
id name Chess Engine
id author John Smith

// ENGINE: send the options that can be changed
// in this case the hash size can have a value from 1 to 128 MB
option name Hash type spin default 1 min 1 max 128

// ENGINE: sent all parameters and is ready
uciok

// GUI: set hash to 32 MB
setoption name Hash value 32

// GUI: waiting for the engine to finish initializing
isready

// ENGINE: finished setting up the internal values and is ready to start
readyok

// GUI: let the engine know if starting a new game
ucinewgame

// GUI: tell the engine the position to search
position startpos moves e2e4

// GUI: tell the engine to start searching
// in this case give it the timing information in milliseconds
go wtime 122000 btime 120000 winc 2000 binc 2000

// ENGINE: send search information continuously during search
// this includes depth, search value, time, nodes, speed, and pv line
info depth 1 score cp -1 time 10 nodes 26 nps 633 pv e7e6
info depth 2 score cp -38 time 22 nodes 132 nps 2659 pv e7e6 e2e4
info depth 3 score cp -6 time 31 nodes 533 nps 10690 pv d7d5 e2e3 e7e6
info depth 4 score cp -30 time 55 nodes 1292 nps 25606 pv d7d5 e2e3 e7e6 g1f3

// ENGINE: return the best move found
bestmove d7d5

I've simplified many aspects of the interaction. A fully featured GUI will have to support lots of other commands that you can find in the UCI specification (another source). You can also look at how existing GUIs work. For example, if you use Arena, you can hit F4 to see a log of the command interaction,

Response from my chess engine using Universal Chess Interface (UCI) isn't received by the chess GUI apps

The problem seems to be in using select.select() and/or fileinput.input(). If I omit those fancy techniques and simply read from STDIN, everything works and cutechess accepts my engine. This is the basic code for a UCI chess engine to get recognized:

import sys
import os
import re


if __name__ == '__main__':
while True:
line = input()
tokens = [ x.strip().lower() for x in re.split("\s+", line.strip()) ]
if tokens[0] == "uci":
sys.stdout.write("id name mychess\n")
sys.stdout.write("id author myname\n")
sys.stdout.write("uciok\n")
elif tokens[0] == "isready":
print("readyok")

Of course, the blocking call to input() now doesn't allow for concurrent calculations in my engine while accepting input from the GUI immediately, but that's stuff for perhaps another question.

Displaying UCI commands between a chess engine and Winboard/xboard

An UCI chess engine doesn't run directly in Winboard/XBoard. You have to use an 'interpreter' progream like Polyglot. If you want to know how a chess GUI communicates with an UCI engines use Arena and press F4. If you want to use another GUI you may take a look to UCIPlug.exe.

Google 'polyglot' or 'uciplug' to find out more..

How to setup a custom board with a UCI chess engine (e.g. Stockfish)

The "fenstring" is a special notation for chess positions called Forsyth–Edwards Notation or short FEN.

write an android gui chess interface without ndk

In order to keep the engine running, I had to use the ProcessBuild to create a process.

For that I used the following code:

    process = processBuilder.start(); // To run the engine

//
// Start the thread that will handle the responses of the engine.
//
Thread responseThread = new Thread(runnableobject);
responseThread.start(); // Then treat the response in this file

To get an installed engine, I used the intent "intent.chess.provider.ENGINE"



Related Topics



Leave a reply



Submit