UCB1AMAF: LTREE_DEBUG -> URAVE_DEBUG
[pachi/t.git] / joseki / sgfvar2gtp.pl
blob5b05b6bbac93cd1b1b663737a13c611935539786
1 #!/usr/bin/perl
2 # Convert SGF file to a sequence of GTP games, one game per each variation
3 # that ends with /GOOD/ comment.
5 use warnings;
6 use strict;
8 sub printgame
10 my ($sgf) = @_;
11 my $pt = $sgf->getAddress();
13 my @moves;
14 do {
15 my ($b, $w) = ($sgf->property('B'), $sgf->property('W'));
16 if ($b) { push @moves, ['b', $_] foreach @$b; }
17 if ($w) { push @moves, ['w', $_] foreach @$w; }
18 } while ($sgf->prev());
20 print "boardsize 19\nclear_board\n";
21 for my $move (reverse @moves) {
22 my ($sx, $sy) = @{$move->[1]};
23 my @abcd = split(//, "abcdefghjklmnopqrstuvwxyz");
24 my $x = $sy + 1; my $y = $abcd[18 - $sx];
25 if ("$y$x" eq "z20") {
26 $y = "pass"; $x = "";
28 print "play ".$move->[0]." $y$x\n";
31 $sgf->goto($pt);
34 sub recurse
36 my ($sgf) = @_;
37 my $c = $sgf->property('C');
38 if ($c and $c->[0] =~ /GOOD/) {
39 printgame($sgf);
41 for (0 .. $sgf->branches()-1) {
42 $sgf->gotoBranch($_);
43 recurse($sgf);
44 $sgf->prev();
48 use Games::SGF::Go;
49 my $sgf = new Games::SGF::Go;
51 $sgf->readFile($ARGV[0]);
53 $sgf->gotoRoot();
54 recurse($sgf);