gnugo-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [gnugo-devel] Tests inside SGF files


From: Trevor Morris
Subject: Re: [gnugo-devel] Tests inside SGF files
Date: Wed, 21 Nov 2001 14:22:39 -0500

>My suggestion is that you write a script which converts a game record
>annotated with test cases to the *.tst format. That may give you a
>comfortable way to produce test cases.

OK, I took you up on this.  You can see the results with trevor_1_15.3.

Here's the perl script I used.  It currently only processes SGF files 
without variations, but that's quite useful enough when annotating
games.

The approach I took is quite simple.  All GTP commands are put into
the SGF comment field.  The comment field is interpretted in order:
 1) Lines starting with "#" are copied into the tst file.
 2) owl_attack or owl_defend commands can be put in like:
        owl_attack A1
        1 G2        
 3) Otherwise, a single line is interpretted as the correct answer, with
    the appropriate "gg_genmove" directive added automatically.

Here's the script.  Feel free to add it to the distribution if anyone
else would find it handy:


------ sgf2tst.pl ------
# insert standard GPL disclaimer here. #

use strict;
use warnings;

local $/;
undef $/;

my $probnum = 100;
my $increment = 10;

while (<>) {
  my $content = $_;
  if ($content !~ /C\[/) {
    warn "$ARGV: No comments.";
    next;
  }

  print "\n\n# $ARGV problems:\n\n";
  
  $content =~ s/^\(;//;
  
  my $i=0;
  while ($content =~ /(.*?);/sg) {  # for each node.
    $i++;
    my $node = $1;
    next if $node !~ /C\[(.*)\]/s;
    my $comments = "";
    my $command = "";
    my $comment = $1;
    my ($othercolor) = $node =~ /(W|B)\[/       or die "No W or B move
here: $ARGV($i): $node";
    while ($comment =~ /^(.*)$/mg) { # i.e. for each line of comment
      my $line = $1;
      $line =~ s/\s*$//;
      $line =~ s/^\s*//;
      if ($line =~ /^#/) {
        $comments .= "$line\n";
        next;
      }
      $command .= "loadsgf $ARGV $i\n";
      #$command .= "showboard\n" if 0;
      if ($line =~ /owl_attack|owl_defend/) {
        $command .= "$probnum $line\n";  #ah, this line is a specific gtp
command.
        $comment =~ /^(.*)$/mg;          #read next line for answer.
        $line = $1;
        $line =~ s/\s*$//;
        $line =~ s/^\s*//;
      } else {
        $command .= "$probnum gg_genmove " . ($othercolor eq 'B' ? 'white'
: 'black') . "\n";
      }
      $probnum += $increment;
      $command .= "#? [$line]\n";
      
    }
    print "$comments$command\n\n";# print "\t$i: $1\n";
  }
  
}







reply via email to

[Prev in Thread] Current Thread [Next in Thread]