hello,
how difficult would it be to write a program or script that:
1) on a regular interval, loads input.pgn and starts analyzing the final position of the game in the file
2) on a regular interval, outputs output.pgn containing the game from input.pgn annotated with a score evaluation so far and a PV (while only the last move is analyzed each time, output.pgn would contain all past annotations for the earlier moves)
3) everything built as much as possible using existing tools, like uci engines and scripts
4) running preferrably as a unix script
any suggestions were to start? maybe a UCI library of some sort?
thanks.
how difficult to write a program or script that...
Moderators: hgm, Rebel, chrisw
-
- Posts: 164
- Joined: Wed Dec 23, 2009 1:57 pm
-
- Posts: 5106
- Joined: Tue Apr 29, 2008 4:27 pm
Re: how difficult to write a program or script that...
That is very easy to do, but does require some tool to parse and make sense of PGN files. I wrote my own tcl, java and C package which knows how to parse PGN and a C routine (for linux only) that knows how to connect to a chess program.casaschi wrote:hello,
how difficult would it be to write a program or script that:
1) on a regular interval, loads input.pgn and starts analyzing the final position of the game in the file
2) on a regular interval, outputs output.pgn containing the game from input.pgn annotated with a score evaluation so far and a PV (while only the last move is analyzed each time, output.pgn would contain all past annotations for the earlier moves)
3) everything built as much as possible using existing tools, like uci engines and scripts
4) running preferrably as a unix script
any suggestions were to start? maybe a UCI library of some sort?
thanks.
My pgn parsing routines do not handle comment well, but if you have comments you can strip them out with pgn-extract. Handling comments that are properly formed and nested would be pretty trivial anyway.
You mention using existing tools, I think that might even be possible with a little creativity. pgn-extract can output a pgn file in long algebraic, which is the format you need to send information to a UCI program. with tools like sed, grep, awk, tail, etc you can build a string to send to a uci program in a pipeline. (You can also produce fen strings with pgn-extract but you lose history which may or many not affect the results with respect to drawish positions.)
I have a 20 line tcl script called "plumbing" which lets you put uci commands in a file and send them to a UCI program as if UCI were synchronous. I use it all the time, it's one of those simple things that can be used for everything.
This is all pretty easy to do, just requires a couple of hours of work most of which is debugging and testing. I'm really good at this type of stuff, probably most of the chess developers here are too.
-
- Posts: 20943
- Joined: Mon Feb 27, 2006 7:30 pm
- Location: Birmingham, AL
Re: how difficult to write a program or script that...
If I were going to do this, I would do it inside Crafty I think. Although it is trivial to tell crafty to "read a PGN file and then start to analyze" I think it would make more sense to tell it "read a PGN file, analyze for some amount of time, produce the output.pgn file, and then wait until the PGN input is modified, then read it and repeat...Don wrote:That is very easy to do, but does require some tool to parse and make sense of PGN files. I wrote my own tcl, java and C package which knows how to parse PGN and a C routine (for linux only) that knows how to connect to a chess program.casaschi wrote:hello,
how difficult would it be to write a program or script that:
1) on a regular interval, loads input.pgn and starts analyzing the final position of the game in the file
2) on a regular interval, outputs output.pgn containing the game from input.pgn annotated with a score evaluation so far and a PV (while only the last move is analyzed each time, output.pgn would contain all past annotations for the earlier moves)
3) everything built as much as possible using existing tools, like uci engines and scripts
4) running preferrably as a unix script
any suggestions were to start? maybe a UCI library of some sort?
thanks.
My pgn parsing routines do not handle comment well, but if you have comments you can strip them out with pgn-extract. Handling comments that are properly formed and nested would be pretty trivial anyway.
You mention using existing tools, I think that might even be possible with a little creativity. pgn-extract can output a pgn file in long algebraic, which is the format you need to send information to a UCI program. with tools like sed, grep, awk, tail, etc you can build a string to send to a uci program in a pipeline. (You can also produce fen strings with pgn-extract but you lose history which may or many not affect the results with respect to drawish positions.)
I have a 20 line tcl script called "plumbing" which lets you put uci commands in a file and send them to a UCI program as if UCI were synchronous. I use it all the time, it's one of those simple things that can be used for everything.
This is all pretty easy to do, just requires a couple of hours of work most of which is debugging and testing. I'm really good at this type of stuff, probably most of the chess developers here are too.
That would not be much code to write...
-
- Posts: 164
- Joined: Wed Dec 23, 2009 1:57 pm
Re: how difficult to write a program or script that...
Good idea.If I were going to do this, I would do it inside Crafty I think. Although it is trivial to tell crafty to "read a PGN file and then start to analyze" I think it would make more sense to tell it "read a PGN file, analyze for some amount of time, produce the output.pgn file, and then wait until the PGN input is modified, then read it and repeat...
That would not be much code to write...
I'll start having a look at the crafty code where the "annotate" command is implemented.
-
- Posts: 20943
- Joined: Mon Feb 27, 2006 7:30 pm
- Location: Birmingham, AL
Re: how difficult to write a program or script that...
It is simpler than that.casaschi wrote:Good idea.If I were going to do this, I would do it inside Crafty I think. Although it is trivial to tell crafty to "read a PGN file and then start to analyze" I think it would make more sense to tell it "read a PGN file, analyze for some amount of time, produce the output.pgn file, and then wait until the PGN input is modified, then read it and repeat...
That would not be much code to write...
I'll start having a look at the crafty code where the "annotate" command is implemented.
1. you can force a "read xxx.pgn" command into the input buffer, call Option() and Crafty will read that file in.
2. then force a "st=n" command into the input buffer" to set the target time limit.
3. then call "Iterate()" to search for that long.
Getting the output depends on what you want. You could "ftell()" the log file before you call iterate, then fseek() back to that point and read the log to get all the search output. Or you could maybe use "whisper_text" which has the PV of the last search...
-
- Posts: 5106
- Joined: Tue Apr 29, 2008 4:27 pm
Re: how difficult to write a program or script that...
Yes, I think Crafty has all the support routines you would need.casaschi wrote:Good idea.If I were going to do this, I would do it inside Crafty I think. Although it is trivial to tell crafty to "read a PGN file and then start to analyze" I think it would make more sense to tell it "read a PGN file, analyze for some amount of time, produce the output.pgn file, and then wait until the PGN input is modified, then read it and repeat...
That would not be much code to write...
I'll start having a look at the crafty code where the "annotate" command is implemented.