Help with EPD script?

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

Kingpatzer

Help with EPD script?

Post by Kingpatzer »

Hey guys, I don't know if this is the right forum for questions like this, but I hope so.

I am trying to find a script to allow me to batch analyze EPD files with a UCI engine, preferably on a mac. So something like a bash or perl script that will take a search depth or time as an argument, an engine name, and an EPD file name, and will store the CE value back into the file for each position.

I'm looking to use it with the program CPT, which is basically a free version of bookup that doesn't do positional evaluations in the program.

Does anyone have something like that or would anyone be able to point me in the right direction to get started trying to build it?
tvrzsky
Posts: 128
Joined: Sat Sep 23, 2006 7:10 pm
Location: Prague

Re: Help with EPD script?

Post by tvrzsky »

I am not quite sure what do you want exactly but maybe something like this?
arguments:
[t|d] [time in msec|depth] engine_path epdfile_path
example:
t 880 "C:/Program Files (x86)/Arena/Engines/critter/Critter_1.0_64bit.exe" "E:/work/chessprog/DATABASE/testy/LAPUCE2.EPD"

Code: Select all

#!/usr/bin/perl
use IPC::Open2;

$engine = $ARGV[2];
$epdfile = $ARGV[3];
if ($ARGV[0] eq 't') { $limit = 'movetime' }
elsif ($ARGV[0] eq 'd') { $limit = 'depth' }
else { die ("bad argument: $ARGV[0]") }
die ("bad argument: $ARGV[1]") unless ($ARGV[1] =~ /^\d+$/);
$limit = $limit.' '.$ARGV[1];
$output = ">output.txt";

$engine = open2(*FROMENG, *TOENG, $engine);
TOENG->autoflush(1);
FROMENG->autoflush(1);
$| = 1;                                

open EPDFILE, $epdfile or die ("can't open $epdfile!!!");
open OUTPUT, $output or die ("can't open $output!!!");
print TOENG "uci\n";
while (<EPDFILE>)
&#123;
  if ( m§(?&#58;(?&#58;&#91;1-8KkQqRrBbNnPp&#93;+/)&#123;7&#125;&#91;1-8KkQqRrBbNnPp&#93;+) (?&#58;&#91;wb&#93;) (?&#58;-|K?Q?k?q?) (?&#58;-|&#91;a-h&#93;&#91;1-8&#93;)§o )
  &#123;
    print TOENG "position fen $&\ngo $limit\n";
    my $line = <FROMENG>;
    my $score = '???';
    my $ismate;
    while ($line !~ /bestmove/)
    &#123;
      if ($line =~ /score &#40;cp|mate&#41; (-?\d+) /)
      &#123;
        $score = $2;
        $ismate = $1;
      &#125;
      $line = <FROMENG>;
    &#125;
    chomp;
    print OUTPUT "$_ ".($ismate eq 'mate' ? 'mate ' &#58; '').$score."\n";
  &#125;
&#125;
print TOENG "quit\n";
close EPDFILE;
close TOENG;
close FROMENG;
close OUTPUT;
User avatar
Don
Posts: 5106
Joined: Tue Apr 29, 2008 4:27 pm

Re: Help with EPD script?

Post by Don »

Kingpatzer wrote:Hey guys, I don't know if this is the right forum for questions like this, but I hope so.

I am trying to find a script to allow me to batch analyze EPD files with a UCI engine, preferably on a mac. So something like a bash or perl script that will take a search depth or time as an argument, an engine name, and an EPD file name, and will store the CE value back into the file for each position.

I'm looking to use it with the program CPT, which is basically a free version of bookup that doesn't do positional evaluations in the program.

Does anyone have something like that or would anyone be able to point me in the right direction to get started trying to build it?
I wrote a script called "plumbing" long ago which let's you "script" uci commands. Since UCI is a synchronous protocol, you cannot normally just pipe commands to it, but my script allows this. It essentially feeds the commands you send to the engine but deals with the asynchronous parts, such as waiting for the results of the "go" command which normally blocks execution of other commands that might be sent. It's about 20 lines of tcl code. Same things could easily be done in perl, ruby, lua, etc.

The Unix philosophy is simple tools that connect and enhance each other, so it's easy to use this tool in pipeline with other simple scripts to do cool things.

However, what you actually want is polyglot, which I believe supports exactly what you are asking for. It has an EPD test mode and lot of ways to configure it.

Don
User avatar
Don
Posts: 5106
Joined: Tue Apr 29, 2008 4:27 pm

Re: Help with EPD script?

Post by Don »

I just saw the script by Filip which is probably just as good for what you need too.

Don
Don wrote:
Kingpatzer wrote:Hey guys, I don't know if this is the right forum for questions like this, but I hope so.

I am trying to find a script to allow me to batch analyze EPD files with a UCI engine, preferably on a mac. So something like a bash or perl script that will take a search depth or time as an argument, an engine name, and an EPD file name, and will store the CE value back into the file for each position.

I'm looking to use it with the program CPT, which is basically a free version of bookup that doesn't do positional evaluations in the program.

Does anyone have something like that or would anyone be able to point me in the right direction to get started trying to build it?
I wrote a script called "plumbing" long ago which let's you "script" uci commands. Since UCI is a synchronous protocol, you cannot normally just pipe commands to it, but my script allows this. It essentially feeds the commands you send to the engine but deals with the asynchronous parts, such as waiting for the results of the "go" command which normally blocks execution of other commands that might be sent. It's about 20 lines of tcl code. Same things could easily be done in perl, ruby, lua, etc.

The Unix philosophy is simple tools that connect and enhance each other, so it's easy to use this tool in pipeline with other simple scripts to do cool things.

However, what you actually want is polyglot, which I believe supports exactly what you are asking for. It has an EPD test mode and lot of ways to configure it.

Don