tree_node_merge(): One of merged nodes wouldn't have parent reset properly
[pachi.git] / sgf2gtp.pl
blob700d61d5ff8e825985a1e62148689854fd7f90e2
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 = <>;
11 print "boardsize " . ($sgf =~ /SZ\[(\d+)\]/)[0];
12 print "clear_board";
13 print "komi " . ($sgf =~ /KM\[([\d.]+)\]/)[0];
15 my @m = split /;/, $sgf;
16 foreach (@m) {
17 /^([BW])\[(\w\w)\]/ or next;
18 my ($color, $coord) = ($1, $2);
19 $coord =~ s/i/j/g;
20 my ($x, $y) = split //, $coord;
21 $y =~ tr/abcdefghj/987654321/;
22 print "play $color $x$y";