Call an engine from BASIC?!

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

JBNielsen
Posts: 267
Joined: Thu Jul 07, 2011 10:31 pm
Location: Denmark

Re: Call an engine from BASIC?!

Post by JBNielsen »

I can not make Stockfish accept multiple commands.
It's like the program exits after each command.
So I cannot give it a position and then analyze it.

It works with a single command:
BASIC:
SHELL "SFinput.bat >tempfile.txt"

SFinput.bat:
Stockfish go movetime 9999


But this fails:
BASIC: SHELL "SFinput.bat >tempfile.txt"

SFinput.bat:
Stockfish position startpos moves e2e4
go movetime 5555

And this fails:
BASIC: SHELL "SFinput.bat >tempfile.txt"

SFinput.bat:
Stockfish position startpos moves e2e4
Stockfish go movetime 5555

And this fails:
BASIC: SHELL "Stockfish <SFinput.bat >tempfile.txt"

SFinput.bat:
position startpos moves e2e4
go movetime 5555
Dann Corbit
Posts: 12541
Joined: Wed Mar 08, 2006 8:57 pm
Location: Redmond, WA USA

Re: Call an engine from BASIC?!

Post by Dann Corbit »

Try redirecting the input from a file
stockfish < myfileofcommands.txt
Taking ideas is not a vice, it is a virtue. We have another word for this. It is called learning.
But sharing ideas is an even greater virtue. We have another word for this. It is called teaching.
AlvaroBegue
Posts: 931
Joined: Tue Mar 09, 2010 3:46 pm
Location: New York
Full name: Álvaro Begué (RuyDos)

Re: Call an engine from BASIC?!

Post by AlvaroBegue »

That won't work. The engine doesn't stop reading input while it's thinking. So it will process the end of file and terminate the search. You need to feed it the commands at the right time. I don't know how you do that in BASIC, but I've done it in Perl before and it worked just fine.

From bash this works:
> (echo uci; echo position startpos; echo go infinite; sleep 1; echo quit) | stockfish

If you want something interactive that waits for certain output from the engine, you'll have to program it.
Dann Corbit
Posts: 12541
Joined: Wed Mar 08, 2006 8:57 pm
Location: Redmond, WA USA

Re: Call an engine from BASIC?!

Post by Dann Corbit »

It won't work?
I do it all the time, and have been doing it for years.
Maybe there is an issue with how BASIC deals with pipes
Taking ideas is not a vice, it is a virtue. We have another word for this. It is called learning.
But sharing ideas is an even greater virtue. We have another word for this. It is called teaching.
JBNielsen
Posts: 267
Joined: Thu Jul 07, 2011 10:31 pm
Location: Denmark

Re: Call an engine from BASIC?!

Post by JBNielsen »

Dann Corbit wrote: Mon Jun 01, 2020 7:35 pm Try redirecting the input from a file
stockfish < myfileofcommands.txt
That was my third try...

And this fails:
BASIC: SHELL "Stockfish <SFinput.bat >tempfile.txt"
Dann Corbit
Posts: 12541
Joined: Wed Mar 08, 2006 8:57 pm
Location: Redmond, WA USA

Re: Call an engine from BASIC?!

Post by Dann Corbit »

And this fails:
BASIC: SHELL "Stockfish <SFinput.bat >tempfile.txt"
That syntax is wrong. You do not redirect the batch file of commands into the input of Stockfish, which will not understand the commands.
You should use the SF version I modified, because it will exit when it completes the analysis.
The input for stockfish should consist of exactly this:

Code: Select all

Any UCI commands you want to use initialize the analysis
The benchmark command
No more and no less.
you will redirect the output of stockfish to the output file you wish.
Taking ideas is not a vice, it is a virtue. We have another word for this. It is called learning.
But sharing ideas is an even greater virtue. We have another word for this. It is called teaching.
JBNielsen
Posts: 267
Joined: Thu Jul 07, 2011 10:31 pm
Location: Denmark

Re: Call an engine from BASIC?!

Post by JBNielsen »

Thanks for input.

The funny thing is that Dabbaba (which I have programmed in C) accepts multiple commands when started from Basic.
I will do some more attempts....


This works OK:
BASIC:
SHELL "StartDabbaba.bat"

StartDabbaba.bat:
dabbaba <DabbaAnaInput.bat

DabbaAnaInput.bat:
help
8
d4g5ana.pgn
1
JBNielsen
Posts: 267
Joined: Thu Jul 07, 2011 10:31 pm
Location: Denmark

Re: Call an engine from BASIC?!

Post by JBNielsen »

I am doing much better now; thanks for help!
I can execute more commands now.... BUT:

The last go-command always fails.
The 'error' I get is one line with this strange result: "bestmove a2a3 ponder f5e4"
(see below)

I am still confused....
But I can live with that.
I can just insert an extra go-command and ignore the result.

INPUT
go movetime 222
position startpos moves e2e4 f7f5
go movetime 333
go movetime 444
go movetime 555
go movetime 666

OUTPUT

Code: Select all

Stockfish 301216 by T. Romstad, M. Costalba, J. Kiiski, G. Linscott
info depth 1 seldepth 1 multipv 1 score cp 90 nodes 20 nps 10000 tbhits 0 time 2 pv e2e4
info depth 2 seldepth 2 multipv 1 score cp 92 nodes 47 nps 23500 tbhits 0 time 2 pv e2e4 b7b6
info depth 3 seldepth 3 multipv 1 score cp 119 nodes 133 nps 66500 tbhits 0 time 2 pv d2d4 d7d6 e2e4
info depth 4 seldepth 4 multipv 1 score cp 15 nodes 614 nps 122800 tbhits 0 time 5 pv g1f3 d7d5 d2d4 e7e6
info depth 5 seldepth 5 multipv 1 score cp 51 nodes 1328 nps 166000 tbhits 0 time 8 pv e2e4 d7d5 e4e5 d5d4 g1f3
info depth 6 seldepth 6 multipv 1 score cp 27 nodes 2457 nps 204750 tbhits 0 time 12 pv e2e4 b8c6 d2d4 d7d5 e4e5 e7e6
info depth 7 seldepth 7 multipv 1 score cp 14 nodes 5217 nps 193222 tbhits 0 time 27 pv g1f3 d7d5 d2d4 g8f6 e2e3 e7e6 c2c3
info depth 8 seldepth 8 multipv 1 score cp 7 nodes 10298 nps 257450 tbhits 0 time 40 pv d2d4 d7d5 b1c3 c8f5 e2e3 e7e6 g1f3 b8c6
info depth 9 seldepth 9 multipv 1 score cp 34 nodes 16846 nps 295543 tbhits 0 time 57 pv b1c3 d7d5 d2d4 c8f5 g1f3 b8c6 h2h3 e7e6 e2e3
info depth 10 seldepth 13 multipv 1 score cp 47 nodes 33149 nps 208484 tbhits 0 time 159 pv e2e4 d7d5 e4d5 g8f6 c2c4 e7e6 d5e6 f8c5 g1e2 b8c6 e6f7 e8f7 b1c3
info depth 11 seldepth 17 multipv 1 score cp 55 nodes 55233 nps 221819 tbhits 0 time 249 pv e2e4
bestmove e2e4 ponder d7d5
info depth 1 seldepth 1 multipv 1 score cp 142 nodes 37 nps 148 tbhits 0 time 250 pv e4f5
info depth 2 seldepth 2 multipv 1 score cp 242 nodes 83 nps 332 tbhits 0 time 250 pv e4e5 g8f6 e5f6 e7f6
info depth 3 seldepth 3 multipv 1 score cp 242 nodes 128 nps 512 tbhits 0 time 250 pv e4e5 g8f6 e5f6
info depth 4 seldepth 4 multipv 1 score cp 231 nodes 263 nps 1052 tbhits 0 time 250 pv e4e5 f5f4 d2d4 d7d5 c1f4
info depth 5 seldepth 6 multipv 1 score cp 107 nodes 1449 nps 5704 tbhits 0 time 254 pv e4f5 g7g6 f5g6 g8f6 d2d4 h7g6
info depth 6 seldepth 6 multipv 1 score cp 107 nodes 2217 nps 8461 tbhits 0 time 262 pv e4f5 g7g6 f5g6 g8f6 d2d4 h7g6
info depth 7 seldepth 7 multipv 1 score cp 106 nodes 4137 nps 15494 tbhits 0 time 267 pv e4e5 e7e6 d2d4 g8e7 g1f3 b8c6 b1c3
info depth 8 seldepth 8 multipv 1 score cp 111 nodes 5075 nps 18866 tbhits 0 time 269 pv e4e5 e7e6 d2d4 g8e7 g1f3 b8c6 b1c3 d7d5
info depth 9 seldepth 10 multipv 1 score cp 105 nodes 10743 nps 38505 tbhits 0 time 279 pv e4e5 e7e6 d2d4 g8e7 c1g5 h7h6 g5h4 b8c6 b1c3 d7d6
info depth 10 seldepth 14 multipv 1 score cp 138 nodes 29397 nps 89899 tbhits 0 time 327 pv e4f5 g8f6 d2d4 d7d6 f1d3 e7e5 f5e6 c8e6 d1e2 d8e7 b1c3
info depth 11 seldepth 16 multipv 1 score cp 145 nodes 38451 nps 112759 tbhits 0 time 341 pv e4f5
bestmove e4f5 ponder g8f6
info depth 1 seldepth 1 multipv 1 score cp 145 nodes 33 nps 351 tbhits 0 time 94 pv e4f5
info depth 2 seldepth 2 multipv 1 score cp 145 nodes 66 nps 702 tbhits 0 time 94 pv e4f5 g8f6
info depth 3 seldepth 3 multipv 1 score cp 145 nodes 101 nps 1074 tbhits 0 time 94 pv e4f5 g8f6 d2d4
info depth 4 seldepth 4 multipv 1 score cp 152 nodes 143 nps 1521 tbhits 0 time 94 pv e4f5 g8f6 d2d4 d7d6
info depth 5 seldepth 5 multipv 1 score cp 147 nodes 271 nps 2882 tbhits 0 time 94 pv e4f5 e7e6 f5e6 d7e6 d2d4
info depth 6 seldepth 6 multipv 1 score cp 153 nodes 455 nps 4840 tbhits 0 time 94 pv e4f5 g8f6 d2d4 d7d5 f1d3 e7e6
info depth 7 seldepth 7 multipv 1 score cp 153 nodes 699 nps 7436 tbhits 0 time 94 pv e4f5 g8f6 d2d4 d7d5 f1d3 e7e6 g1f3
info depth 8 seldepth 8 multipv 1 score cp 153 nodes 945 nps 10053 tbhits 0 time 94 pv e4f5 g8f6 d2d4 d7d5 f1d3 e7e6 g1f3 e6f5
info depth 9 seldepth 12 multipv 1 score cp 165 nodes 2202 nps 22937 tbhits 0 time 96 pv e4f5 g8f6 d2d4 e7e6 f5e6 d8e7 d1e2 e7e6 e2e6 d7e6
info depth 10 seldepth 15 multipv 1 score cp 120 nodes 15613 nps 132313 tbhits 0 time 118 pv e4f5 g8f6 g1f3 e7e6 f1b5 c7c6 b5d3 d7d6 e1g1 e6f5 f1e1 f8e7
info depth 11 seldepth 16 multipv 1 score cp 128 nodes 29286 nps 201972 tbhits 0 time 145 pv e4f5 g8f6 d2d4 d7d5 f1d3 b8c6 g1f3 f6e4 c2c3 c8f5 e1g1 g7g6
info depth 12 seldepth 17 multipv 1 score cp 139 nodes 56513 nps 294338 tbhits 0 time 192 pv e4f5 g8f6 d2d4 d7d5 f1d3 e7e6 g1f3 e6f5 e1g1 b8c6 d3b5 f8e7 f3e5 e8g8 e5c6 b7c6
info depth 13 seldepth 21 multipv 1 score cp 134 nodes 113583 nps 404209 tbhits 0 time 281 pv e4f5 g8f6 d2d4 e7e6 f5e6 d8e7 g1f3 e7e6 d1e2 d7d6 b1c3 e6e2 f1e2 c8f5 e2d3 f5d3 c2d3 b8c6 d4d5
info depth 14 seldepth 25 multipv 1 score cp 141 nodes 208794 nps 465020 tbhits 0 time 449 pv e4f5
bestmove e4f5 ponder g8f6
info depth 1 seldepth 1 multipv 1 score cp 141 nodes 33 nps 92 tbhits 0 time 358 pv e4f5
info depth 2 seldepth 2 multipv 1 score cp 141 nodes 68 nps 189 tbhits 0 time 358 pv e4f5 g8f6
info depth 3 seldepth 3 multipv 1 score cp 141 nodes 103 nps 287 tbhits 0 time 358 pv e4f5 g8f6 d2d4 d7d5
info depth 4 seldepth 4 multipv 1 score cp 141 nodes 143 nps 399 tbhits 0 time 358 pv e4f5 g8f6 d2d4 d7d5
info depth 5 seldepth 5 multipv 1 score cp 141 nodes 193 nps 539 tbhits 0 time 358 pv e4f5 g8f6 d2d4 d7d5 f1d3
info depth 6 seldepth 6 multipv 1 score cp 141 nodes 260 nps 726 tbhits 0 time 358 pv e4f5 g8f6 d2d4 d7d5 f1d3 e7e6
info depth 7 seldepth 7 multipv 1 score cp 141 nodes 351 nps 980 tbhits 0 time 358 pv e4f5 g8f6 d2d4 d7d5 f1d3 e7e6 d1e2
info depth 8 seldepth 8 multipv 1 score cp 141 nodes 463 nps 1293 tbhits 0 time 358 pv e4f5 g8f6 d2d4 d7d5 f1d3 e7e6 d1e2 d8e7
info depth 9 seldepth 12 multipv 1 score cp 144 nodes 1235 nps 3440 tbhits 0 time 359 pv e4f5 g8f6 d2d4 d7d6 f1d3 e7e5 f5e6 c8e6 g1f3 e6g4 e1g1
info depth 10 seldepth 15 multipv 1 score cp 149 nodes 2929 nps 8113 tbhits 0 time 361 pv e4f5 g8f6 d2d4 d7d5 f1d3 e7e6 d1e2 d8e7 b1c3 e6f5 c1f4 b8c6
info depth 11 seldepth 16 multipv 1 score cp 145 nodes 4671 nps 12867 tbhits 0 time 363 pv e4f5 g8f6 d2d4 d7d5 f1d3 e7e6 d1e2 f8d6 g1f3 e8g8 f5e6 d8e7 e1g1 e7e6 b1c3 e6e2
info depth 12 seldepth 20 multipv 1 score cp 140 nodes 9345 nps 25256 tbhits 0 time 370 pv e4f5 g8f6 d2d4 d7d5 f1d3 e7e6 d1e2 f8d6 g1f3 d8e7 e1g1 e8g8 f1e1 f8e8 e2d2 b8c6 f5e6 c8e6
info depth 13 seldepth 23 multipv 1 score cp 140 nodes 25494 nps 64378 tbhits 0 time 396 pv e4f5 g8f6 d2d4 d7d5 f1d3 e7e6 d1e2 f8d6 g1f3 d8e7 e1g1 e6f5 e2e7 e8e7 b1c3 b8c6 c3b5 f6e4 b5d6
info depth 14 seldepth 23 multipv 1 score cp 133 nodes 111408 nps 199655 tbhits 0 time 558 pv e4f5 g8f6
bestmove e4f5 ponder g8f6
bestmove a2a3 ponder f5e4
The next task in my project is to convert pgn-games in short notation into e2e4 d7d5 etc. or into epd's.
Dann Corbit
Posts: 12541
Joined: Wed Mar 08, 2006 8:57 pm
Location: Redmond, WA USA

Re: Call an engine from BASIC?!

Post by Dann Corbit »

JBNielsen wrote: Tue Jun 02, 2020 8:22 pm The next task in my project is to convert pgn-games in short notation into e2e4 d7d5 etc. or into epd's.
PGN-Extract by David Barnes can do that (and more):
https://www.cs.kent.ac.uk/people/staff/djb/pgn-extract/
Here are the output formatting options:

Code: Select all

-W[cm|epd|halg|lalg|elalg|xlalg|xolalg|san|uci] - specify the output format to use.
Default (i.e., without this flag) is SAN.
-W (without anything following) selects the input format. I don't know if the output produced is still valid.
-Wepd is EPD format.
-Whalg is hyphenated long algebraic.
-Wlalg is long algebraic
-Welalg[PNBRQK] is enhanced long algebraic. Use the characters PNBRQK for language specific output, e.g: -WelalgBSLTDK for German.
-Wxlalg[PNBRQK] is enhanced long algebraic with hyphens for non-capture moves and x's for capture moves. Use the characters PNBRQK for language specific output, e.g: -WxlalgBSLTDK for German.
-Wxolalg[PNBRQK] is -Wxlalg but with O-O and O-O-O for castling.
-Wsan[PNBRQK] Use the characters PNBRQK for language specific output, e.g: -WsanBSLTDK for German.
-Wuci is output compatible with the UCI protocol.
-Wcm is a legacy option that output ChessMaster format.
I also use PGN2FEN, which is very nice:
http://www.pgn2fen.com-about.com/
Taking ideas is not a vice, it is a virtue. We have another word for this. It is called learning.
But sharing ideas is an even greater virtue. We have another word for this. It is called teaching.
JBNielsen
Posts: 267
Joined: Thu Jul 07, 2011 10:31 pm
Location: Denmark

Re: Call an engine from BASIC?!

Post by JBNielsen »

Dann Corbit wrote: Tue Jun 02, 2020 8:35 pm
JBNielsen wrote: Tue Jun 02, 2020 8:22 pm The next task in my project is to convert pgn-games in short notation into e2e4 d7d5 etc. or into epd's.
PGN-Extract by David Barnes can do that (and more):
https://www.cs.kent.ac.uk/people/staff/djb/pgn-extract/
Here are the output formatting options:

Code: Select all

-W[cm|epd|halg|lalg|elalg|xlalg|xolalg|san|uci] - specify the output format to use.
Default (i.e., without this flag) is SAN.
-W (without anything following) selects the input format. I don't know if the output produced is still valid.
-Wepd is EPD format.
-Whalg is hyphenated long algebraic.
-Wlalg is long algebraic
-Welalg[PNBRQK] is enhanced long algebraic. Use the characters PNBRQK for language specific output, e.g: -WelalgBSLTDK for German.
-Wxlalg[PNBRQK] is enhanced long algebraic with hyphens for non-capture moves and x's for capture moves. Use the characters PNBRQK for language specific output, e.g: -WxlalgBSLTDK for German.
-Wxolalg[PNBRQK] is -Wxlalg but with O-O and O-O-O for castling.
-Wsan[PNBRQK] Use the characters PNBRQK for language specific output, e.g: -WsanBSLTDK for German.
-Wuci is output compatible with the UCI protocol.
-Wcm is a legacy option that output ChessMaster format.
I also use PGN2FEN, which is very nice:
http://www.pgn2fen.com-about.com/
Oh, thank you very much!!

I'll try to make it work - from BASIC :roll: