Read list of commands from stdin

Code, algorithms, languages, construction...

Read list of commands from stdin

Postby quantum » Thu Sep 14, 2017 9:36 am

I created a file which contains a list with commands.

Code: Select all
isready
ucinewgame
position startpos moves h2h3
go depth 6
quit


Now I want the engine to read that list from stdin

Code: Select all
./engine < cmdlist > output


Using Demolito everything works as expected

Code: Select all
readyok
info depth 1 score cp 41 time 0 nodes 21 pv e7e5
info depth 2 score cp 8 time 0 nodes 133 pv e7e5 e2e4
info depth 3 score cp 33 time 0 nodes 331 pv e7e5 e2e3 d8h4
info depth 4 score cp 8 time 1 nodes 1011 pv b8c6 e2e3 e7e6 b1c3
info depth 5 score cp 44 time 2 nodes 2365 pv b8c6 b1c3 e7e5 c3d5 c6d4
info depth 6 score cp 0 time 7 nodes 8929 pv b8c6 b1c3 e7e6 d2d4 d7d5 g1f3
bestmove b8c6 ponder b1c3


When using e.g. stockfish the output is

Code: Select all
Stockfish 130917 64 BMI2 by T. Romstad, M. Costalba, J. Kiiski, G. Linscott
readyok
bestmove a7a6


and the engine is not searching at all.
I am not very experienced with this kind of stuff. Does anybody knows quick way to fix this?
quantum
 
Posts: 28
Joined: Mon Dec 19, 2011 12:19 am

Re: Read list of commands from stdin

Postby H.G.Muller » Thu Sep 14, 2017 7:05 pm

Well, for one you have to start with a line 'uci' to be UCI compliant, and there is no way to predict how engines will react if you don't comply with the specs. As Stockfish does something, this is probably not the problem, though.

Does the same thing happen when you run Stockfish from the command line? It could be that depth 6 is just too little for Stockfish, that it only starts to print output for depth > 8 or so. (There have been many complaints that PVs and scores of depths below 8 were totally nonsensical, and suppressing the output would be a good way to get rid of such complaints.)
H.G.Muller
 
Posts: 177
Joined: Sun Jul 14, 2013 10:00 am

Re: Read list of commands from stdin

Postby quantum » Thu Sep 14, 2017 9:51 pm

When I type all command into the command line everything works fine:

Code: Select all
Stockfish 130917 64 BMI2 by T. Romstad, M. Costalba, J. Kiiski, G. Linscott
uci
id name Stockfish 130917 64 BMI2
id author T. Romstad, M. Costalba, J. Kiiski, G. Linscott

option name Debug Log File type string default
option name Contempt type spin default 0 min -100 max 100
option name Threads type spin default 1 min 1 max 512
option name Hash type spin default 16 min 1 max 1048576
option name Clear Hash type button
option name Ponder type check default false
option name MultiPV type spin default 1 min 1 max 500
option name Skill Level type spin default 20 min 0 max 20
option name Move Overhead type spin default 60 min 0 max 5000
option name nodestime type spin default 0 min 0 max 10000
option name UCI_Chess960 type check default false
option name SyzygyPath type string default <empty>
option name SyzygyProbeDepth type spin default 1 min 1 max 100
option name Syzygy50MoveRule type check default true
option name SyzygyProbeLimit type spin default 6 min 0 max 6
uciok
isready
readyok
ucinewgame
position startpos moves h2h3
go depth 6
info depth 1 seldepth 1 multipv 1 score cp 90 nodes 20 nps 20000 tbhits 0 time 1 pv e7e5
info depth 2 seldepth 2 multipv 1 score cp 85 nodes 51 nps 51000 tbhits 0 time 1 pv e7e5 b2b3
info depth 3 seldepth 3 multipv 1 score cp 93 nodes 99 nps 99000 tbhits 0 time 1 pv e7e5 b2b3 f8c5
info depth 4 seldepth 4 multipv 1 score cp 3 nodes 395 nps 197500 tbhits 0 time 2 pv e7e5 b2b3 d8f6 e2e4
info depth 5 seldepth 5 multipv 1 score cp 6 nodes 812 nps 270666 tbhits 0 time 3 pv e7e5 b2b3 b7b6 e2e4 d8f6
info depth 6 seldepth 6 multipv 1 score cp -6 nodes 2126 nps 354333 tbhits 0 time 6 pv e7e5 d2d4 d8e7 d4d5 e7c5 d1d2
bestmove e7e5 ponder d2d4
quit


When using the old Stockfish 1.7.1 everything works when I use the list.
Code: Select all
Stockfish 1.7.1 64bit. By Tord Romstad, Marco Costalba, Joona Kiiski.
Good! CPU has hardware POPCNT. We will use it.
id name Stockfish 1.7.1 64bit
id author Tord Romstad, Marco Costalba, Joona Kiiski

option name Use Search Log type check default false
option name Search Log Filename type string default SearchLog.txt
option name Book File type string default book.bin
option name Mobility (Middle Game) type spin default 100 min 0 max 200
option name Mobility (Endgame) type spin default 100 min 0 max 200
option name Pawn Structure (Middle Game) type spin default 100 min 0 max 200
option name Pawn Structure (Endgame) type spin default 100 min 0 max 200
option name Passed Pawns (Middle Game) type spin default 100 min 0 max 200
option name Passed Pawns (Endgame) type spin default 100 min 0 max 200
option name Space type spin default 100 min 0 max 200
option name Aggressiveness type spin default 100 min 0 max 200
option name Cowardice type spin default 100 min 0 max 200
option name Check Extension (PV nodes) type spin default 2 min 0 max 2
option name Check Extension (non-PV nodes) type spin default 1 min 0 max 2
option name Single Evasion Extension (PV nodes) type spin default 2 min 0 max 2
option name Single Evasion Extension (non-PV nodes) type spin default 2 min 0 max 2
option name Mate Threat Extension (PV nodes) type spin default 0 min 0 max 2
option name Mate Threat Extension (non-PV nodes) type spin default 0 min 0 max 2
option name Pawn Push to 7th Extension (PV nodes) type spin default 1 min 0 max 2
option name Pawn Push to 7th Extension (non-PV nodes) type spin default 1 min 0 max 2
option name Passed Pawn Extension (PV nodes) type spin default 1 min 0 max 2
option name Passed Pawn Extension (non-PV nodes) type spin default 0 min 0 max 2
option name Pawn Endgame Extension (PV nodes) type spin default 2 min 0 max 2
option name Pawn Endgame Extension (non-PV nodes) type spin default 2 min 0 max 2
option name Randomness type spin default 0 min 0 max 10
option name Minimum Split Depth type spin default 7 min 4 max 7
option name Maximum Number of Threads per Split Point type spin default 5 min 4 max 8
option name Threads type spin default 8 min 1 max 8
option name Hash type spin default 32 min 4 max 8192
option name Clear Hash type button
option name New Game type button
option name Ponder type check default true
option name OwnBook type check default true
option name MultiPV type spin default 1 min 1 max 500
option name UCI_Chess960 type check default false
option name UCI_AnalyseMode type check default false
option name Zugzwang detection type check default false
uciok
readyok
info depth 1
info depth 1 score cp 68 time 5 nodes 20 nps 4000 pv g8f6
info depth 2
info depth 2 score cp 0 time 5 nodes 49 nps 9800 pv b8c6 g1f3
info depth 3
info depth 3 score cp 56 time 5 nodes 147 nps 29400 pv b8c6 g1f3 g8f6
info depth 4
info depth 4 score cp -4 time 6 nodes 290 nps 48333 pv b8c6 g1f3 g8f6 b1c3
info depth 5
info depth 5 score cp 12 time 6 nodes 607 nps 101166 pv b8c6 g1f3 g8f6 b1c3 e7e5
info depth 6
info depth 6 score cp -4 time 6 nodes 1072 nps 178666 pv b8c6 g1f3 g8f6 b1c3 e7e5 e2e4
info nodes 1483 nps 247166 time 6 hashfull 0
bestmove b8c6 ponder g1f3


So it seems that it somehow depends on the engine...
quantum
 
Posts: 28
Joined: Mon Dec 19, 2011 12:19 am

Re: Read list of commands from stdin

Postby H.G.Muller » Sat Sep 16, 2017 10:38 am

I guess it is a bit tricky. In principle UCI engines should keep reading input even when searching. Because they can get a 'stop' or 'isready' command at any time. If a UCI engine is running from your script, and keeps reading after "go depth 6", it will encounter the "quit". I can imagine that it immediately executes it, thus aborting the search before it even has begon.
H.G.Muller
 
Posts: 177
Joined: Sun Jul 14, 2013 10:00 am

Re: Read list of commands from stdin

Postby lucasart » Sun Nov 19, 2017 4:48 am

quantum wrote:I created a file which contains a list with commands.

Code: Select all
isready
ucinewgame
position startpos moves h2h3
go depth 6
quit


Now I want the engine to read that list from stdin

Code: Select all
./engine < cmdlist > output


Using Demolito everything works as expected

Code: Select all
readyok
info depth 1 score cp 41 time 0 nodes 21 pv e7e5
info depth 2 score cp 8 time 0 nodes 133 pv e7e5 e2e4
info depth 3 score cp 33 time 0 nodes 331 pv e7e5 e2e3 d8h4
info depth 4 score cp 8 time 1 nodes 1011 pv b8c6 e2e3 e7e6 b1c3
info depth 5 score cp 44 time 2 nodes 2365 pv b8c6 b1c3 e7e5 c3d5 c6d4
info depth 6 score cp 0 time 7 nodes 8929 pv b8c6 b1c3 e7e6 d2d4 d7d5 g1f3
bestmove b8c6 ponder b1c3


When using e.g. stockfish the output is

Code: Select all
Stockfish 130917 64 BMI2 by T. Romstad, M. Costalba, J. Kiiski, G. Linscott
readyok
bestmove a7a6


and the engine is not searching at all.
I am not very experienced with this kind of stuff. Does anybody knows quick way to fix this?

The Stockfish behavior is correct, as explained by HGM. The fact that it "works" is actually a bug in Demolito. I'll fix it for the next release. Thing is, I never thought the user would send quit during search. My code only works correctly with stop during search.
"Talk is cheap. Show me the code." -- Linus Torvalds.
lucasart
 
Posts: 197
Joined: Mon Dec 17, 2012 1:09 pm


Return to Programming and Technical Discussions

Who is online

Users browsing this forum: No registered users and 1 guest