# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# This program is distributed with GNU Go, a Go program. #
# Write gnugo@gnu.org or see http://www.gnu.org/software/gnugo/ #
# for more information. #
# Copyright 1999, 2000, 2001 by the Free Software Foundation. #
# This program is free software; you can redistribute it and/or #
# modify it under the terms of the GNU General Public License #
# as published by the Free Software Foundation - version 3, #
# or (at your option) any later version. #
# This program is distributed in the hope that it will be #
# useful, but WITHOUT ANY WARRANTY; without even the implied #
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR #
# PURPOSE. See the GNU General Public License in file COPYING #
# You should have received a copy of the GNU General Public #
# License along with this program; if not, write to the Free #
# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, #
# Boston, MA 02111, USA. #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# This is a script which converts a game record annotated with test cases to
# The script currently only processes SGF files without variations, but that's
# quite useful enough when annotating games.
# All GTP commands are put into the SGF comment field. The comment field is
# 1) Lines starting with "#" are copied into the tst file.
# 2) owl_attack, owl_defend, attack, defend, and eval_eye commands can
# 3) Otherwise, a single line is interpreted as the correct answer, with
# the appropriate "gg_genmove" directive added automatically.
# See regression/trevora.tst for examples. The sgf files for this test
# are in regression/games/trevor/auto/a??.sgf
print STDERR
"Warning : $ARGV : No comments.\n";
print "\n\n# $ARGV problems:\n\n";
while ($content =~ /(.*?);/sg && ($done=1)) { # for each node.
print "CONTENT:'$content':CONTENT\n\n" if $DEBUG;
print "NODE:'$node':NODE\n\n" if $DEBUG;
next if $node !~ /C\[(.*)\]/s ;
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
$command .= "loadsgf $ARGV $i\n";
my $probnum = $autoprobnum;
if ($line =~ /^([0-9]*)\s*((?:owl_attack|attack|owl_defend|defend|eval_eye).*)$/) {
$autoprobnum -= $increment;
$command .= "$probnum $2\n"; #ah, this line is a specific gtp command.
$comment =~ /^(.*)$/mg; #read next line for answer.
$command .= "$probnum gg_genmove " . ($othercolor eq 'B' ?
'white' : 'black') . "\n";
$autoprobnum += $increment;
$command .= "#? [$line]*\n";
print $command if $DEBUG;
print "$comments$command\n\n";