board_gamma_update(): Export function
[pachi.git] / sgf2gtp.pl
blob0c0e14af6722dcbffee85d6ea2899bc6f36ba15f
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];
12 print "boardsize " . $size;
13 print "clear_board";
14 print "komi " . ($sgf =~ /KM\[([\d.]+)\]/)[0];
16 my $abcd = "abcdefghijklmnopqrstuvwxyz";
18 my @m = split /;/, $sgf;
19 foreach (@m) {
20 /^([BW])\[\]/ and print "play $1 pass";
21 /^([BW])\[(\w\w)\]/ or next;
22 my ($color, $coord) = ($1, $2);
23 my ($x, $y) = split //, $coord;
24 ($x ge 'i') and $x++;
25 $y = $size - index($abcd, $y);
26 print "play $color $x$y";