UCI question

Discussion of chess software programming and technical issues.

Moderators: hgm, Harvey Williamson, bob

Forum rules
This textbox is used to restore diagrams posted with the [d] tag before the upgrade.
User avatar
Rebel
Posts: 4257
Joined: Thu Aug 18, 2011 10:04 am

UCI question

Post by Rebel » Mon Jan 28, 2019 7:17 am

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: 45
Joined: Thu Jul 05, 2018 11:09 pm
Location: Chicago, IL
Full name: Josh Odom

Re: UCI question

Post by odomobo » Mon Jan 28, 2019 8:18 am

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: 22894
Joined: Fri Mar 10, 2006 9:06 am
Location: Amsterdam
Full name: H G Muller
Contact:

Re: UCI question

Post by hgm » Mon Jan 28, 2019 8:59 am

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: 4257
Joined: Thu Aug 18, 2011 10:04 am

Re: UCI question

Post by Rebel » Mon Jan 28, 2019 10:19 am

hgm wrote:
Mon Jan 28, 2019 8: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: 779
Joined: Sun May 23, 2010 11:32 am
Contact:

Re: UCI question

Post by elcabesa » Mon Jan 28, 2019 10: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.

User avatar
Rebel
Posts: 4257
Joined: Thu Aug 18, 2011 10:04 am

Re: UCI question

Post by Rebel » Mon Jan 28, 2019 11:46 am

elcabesa wrote:
Mon Jan 28, 2019 10: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: 912
Joined: Tue Mar 09, 2010 2:46 pm
Location: New York
Full name: Álvaro Begué (RuyDos)

Re: UCI question

Post by AlvaroBegue » Mon Jan 28, 2019 12:54 pm

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: 45
Joined: Thu Jul 05, 2018 11:09 pm
Location: Chicago, IL
Full name: Josh Odom

Re: UCI question

Post by odomobo » Mon Jan 28, 2019 4:46 pm

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: 779
Joined: Sun May 23, 2010 11:32 am
Contact:

Re: UCI question

Post by elcabesa » Mon Jan 28, 2019 6:53 pm

You can also use "python chess" library and python scripts to communicate with an uci engine.

jdart
Posts: 3663
Joined: Fri Mar 10, 2006 4:23 am
Location: http://www.arasanchess.org

Re: UCI question

Post by jdart » Mon Jan 28, 2019 8:19 pm

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

Post Reply