2 # This is a naive Perl script that will convert SGF files to GTP
3 # format so that you can feed them to Pachi, insert genmove at
4 # the right places etc. Might not work on obscure SGF files,
5 # and of course there must be no variations.
9 local $/ = undef; my $sgf = <>;
10 my $size = ($sgf =~ /SZ\[(\d+)\]/)[0];
11 $sgf =~ s/\bC\[.*?\]//gs; # no comments
12 #$sgf =~ s/\).*//gs; # cut at end of principal branch
14 print "boardsize " . $size;
16 print "komi " . ($sgf =~ /KM\[([\d.]+)\]/)[0];
18 my $abcd = "abcdefghijklmnopqrstuvwxyz";
20 my @m = split /;/, $sgf;
22 /^([BW])\[\]/ and print "play $1 pass";
23 /^([BW])\[(\w\w)\]/ or next;
24 my ($color, $coord) = ($1, $2);
25 my ($x, $y) = split //, $coord;
27 $y = $size - index($abcd, $y);
28 print "play $color $x$y";