UCI question

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

User avatar
Rebel
Posts: 6991
Joined: Thu Aug 18, 2011 12:04 pm

UCI question

Post by Rebel »

I am not very familiar with UCI since my engine is Winboard. Here is my question:

#1. Start an UCI engine from the command line.
#2. Paste (type) a position, for example

Code: Select all

position fen r1bk1n1r/pp1n1q1p/2p2p1R/3p4/3PpN2/2NB2Q1/PPP2PP1/2K1R3 w - -
#3. type go movetime 1000

And the position is analysed for one second. So far so good.

But what I want is to automate this in one call either from the command line or batch file.

. Komodo position fen r1bk1n1r/pp1n1q1p/2p2p1R/3p4/3PpN2/2NB2Q1/PPP2PP1/2K1R3 w - - go movetime 1000
. Komodo go movetime 1000 position fen r1bk1n1r/pp1n1q1p/2p2p1R/3p4/3PpN2/2NB2Q1/PPP2PP1/2K1R3 w - -

Neither of them work, but I know it somehow is possible because I have done it before, I just forgot.
90% of coding is debugging, the other 10% is writing bugs.
odomobo
Posts: 96
Joined: Fri Jul 06, 2018 1:09 am
Location: Chicago, IL
Full name: Josh Odom

Re: UCI question

Post by odomobo »

The UCI protocol says nothing about command line arguments. I am guessing you were using some engine-specific feature. Do you know which engine you were using?

Also, it sounds really useful to have a standard "interface" for executing commands using command-line parameters. It would simplify certain forms of engine testing.
User avatar
hgm
Posts: 27790
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: UCI question

Post by hgm »

It would be a violation of UCI protocol not to perform the initial handshake (uci - uciok - isready - readyok) before you issue any position-move and go commands. If a UCI engine doesn't crash when you omit that, it is purely by accident. It might not have allocated any hash memory at all, or just a symbolic amount (like 1MB).

As pointed out, the required commands should not be on the command line, but offered as iput. So your script shoul looke like

Code: Select all

komodo.exe
uci
setoption name Hash value 256
isready
position fen <FEN>
go movetime 1000
After that it gets tricky, as you should really wait until the search is finished before you are allowed to send any new commands. And I don't know how you can do that from a script. You could of course start a new Komodo instance, but this would then run in parallel.

If you want to submit a set of positions to the same engine, why not just run it in a regular GUI as a test suite? If you want to save all engine output, you can get that from the debug log.
User avatar
Rebel
Posts: 6991
Joined: Thu Aug 18, 2011 12:04 pm

Re: UCI question

Post by Rebel »

hgm wrote: Mon Jan 28, 2019 9:59 am

Code: Select all

komodo.exe
uci
setoption name Hash value 256
isready
position fen <FEN>
go movetime 1000
Okay, so how does one run that from a batch file?

My (original) question.
90% of coding is debugging, the other 10% is writing bugs.
elcabesa
Posts: 855
Joined: Sun May 23, 2010 1:32 pm

Re: UCI question

Post by elcabesa »

Probably something like that:

Save the command list in input.txt file and then:
Komodo <input.txt

Pay attention the it's not possible to analyze more than one position with a single file because uci require when performing analysis the input management is not blocked.
User avatar
Rebel
Posts: 6991
Joined: Thu Aug 18, 2011 12:04 pm

Re: UCI question

Post by Rebel »

elcabesa wrote: Mon Jan 28, 2019 11:35 am Probably something like that:

Save the command list in input.txt file and then:
Komodo <input.txt

Pay attention the it's not possible to analyze more than one position with a single file because uci require when performing analysis the input management is not blocked.
Works for the purpose I have in mind, thanks!
90% of coding is debugging, the other 10% is writing bugs.
AlvaroBegue
Posts: 931
Joined: Tue Mar 09, 2010 3:46 pm
Location: New York
Full name: Álvaro Begué (RuyDos)

Re: UCI question

Post by AlvaroBegue »

If you have access to Perl, you can have much more control, like this:

Code: Select all

perl -e '$|=1; print "uci\nisready\nposition fen r1bk1n1r/pp1n1q1p/2p2p1R/3p4/3PpN2/2NB2Q1/PPP2PP1/2K1R3 w - -\ngo movetime 1000\n"; sleep (2); print "quit\n"' | stockfish
odomobo
Posts: 96
Joined: Fri Jul 06, 2018 1:09 am
Location: Chicago, IL
Full name: Josh Odom

Re: UCI question

Post by odomobo »

If the perl script doesn't work for you (which it might), you might be able to write an expect script. Expect will wait for certain conditions before proceeding. That way, for example, the script can wait for "readyok" before sending "position ...", and wait for "bestmove ..." before sending "quit"
elcabesa
Posts: 855
Joined: Sun May 23, 2010 1:32 pm

Re: UCI question

Post by elcabesa »

You can also use "python chess" library and python scripts to communicate with an uci engine.
jdart
Posts: 4366
Joined: Fri Mar 10, 2006 5:23 am
Location: http://www.arasanchess.org

Re: UCI question

Post by jdart »

I have a script to do analysis on EPD files. It takes several command-line options, to specify engine, time control, multipv, etc. It uses python-chess.

See https://github.com/jdart1/arasan-chess/ ... analyze.py

Usage:

python3 analyze.py -e <engine> -c <cores> -H <hash in MB> -m <multipv lines> filename.

--Jon