elo_check_probdist(): Refer to b->f[i] as c
[pachi/derm.git] / sgf2gtp.pl
blobfbcf2cb01889eba38cf319d4b84b7d85f564f88c
1 #!/usr/bin/perl -l
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.
7 use warnings;
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;
15 print "clear_board";
16 print "komi " . ($sgf =~ /KM\[([\d.]+)\]/)[0];
18 my $abcd = "abcdefghijklmnopqrstuvwxyz";
20 my @m = split /;/, $sgf;
21 foreach (@m) {
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;
26 ($x ge 'i') and $x++;
27 $y = $size - index($abcd, $y);
28 print "play $color $x$y";