| 1 |
elmex |
1.1 |
#!/opt/perl/bin/perl |
| 2 |
|
|
use strict; |
| 3 |
|
|
use Glib; |
| 4 |
|
|
use Gtk2 -init; |
| 5 |
|
|
use Games::Go::SimpleBoard; |
| 6 |
|
|
use Gtk2::GoBoard; |
| 7 |
|
|
use Games::Go::SGF::Grove; |
| 8 |
|
|
|
| 9 |
|
|
sub read_sgf { |
| 10 |
|
|
my ($file) = @_; |
| 11 |
|
|
|
| 12 |
|
|
open my $sgff, $file or die "$!"; |
| 13 |
|
|
|
| 14 |
|
|
my $c = do { local $/; <$sgff> }; |
| 15 |
|
|
|
| 16 |
|
|
my $sgp = Games::Go::SGF::Grove::Parser->new; |
| 17 |
|
|
my $tree = $sgp->parse ($c); |
| 18 |
|
|
|
| 19 |
|
|
use Data::Dumper; |
| 20 |
|
|
print "TREE:".Data::Dumper::Dumper ([$tree])."\n"; |
| 21 |
|
|
|
| 22 |
|
|
$tree |
| 23 |
|
|
} |
| 24 |
|
|
|
| 25 |
|
|
my $tree = read_sgf $ARGV[0]; |
| 26 |
|
|
|
| 27 |
|
|
my $w = Gtk2::Window->new; |
| 28 |
|
|
|
| 29 |
|
|
$w->add (my $vb = Gtk2::VBox->new); |
| 30 |
|
|
|
| 31 |
|
|
$vb->pack_start (my $hb = Gtk2::HBox->new, 0, 1, 0); |
| 32 |
|
|
$vb->pack_start (my $brd = Gtk2::GoBoard->new (19), 1, 1, 3); |
| 33 |
|
|
|
| 34 |
|
|
$hb->pack_start (my $nb = Gtk2::Button->new_with_label ("next"), 1, 1, 0); |
| 35 |
|
|
|
| 36 |
|
|
my $chlds = shift @{$tree->[0]->[0]->{children}}; |
| 37 |
|
|
my $aw = $tree->[0]->[0]->{AW}; |
| 38 |
|
|
my $ab = $tree->[0]->[0]->{AW}; |
| 39 |
|
|
|
| 40 |
|
|
my @upds; |
| 41 |
|
|
$nb->signal_connect (clicked => sub { |
| 42 |
|
|
my $cur = shift @$chlds; |
| 43 |
|
|
my $sbrd = Games::Go::SimpleBoard->new (19); |
| 44 |
|
|
|
| 45 |
|
|
if ($cur->{W}) { |
| 46 |
|
|
warn "WHITE $cur->{W}->[0] $cur->{W}->[1]\n"; |
| 47 |
|
|
push @upds, [$cur->{W}->[0], $cur->{W}->[1], -1, MARK_W|MARK_MOVE]; |
| 48 |
|
|
} elsif ($cur->{B}) { |
| 49 |
|
|
warn "BLACK $cur->{B}->[0], $cur->{B}->[1]\n"; |
| 50 |
|
|
push @upds, [$cur->{B}->[0], $cur->{B}->[1], -1, MARK_B|MARK_MOVE]; |
| 51 |
|
|
} |
| 52 |
|
|
$sbrd->update ([@upds]); |
| 53 |
|
|
$brd->set_board ($sbrd); |
| 54 |
|
|
}); |
| 55 |
|
|
|
| 56 |
|
|
$w->set_default_size (600, 800); |
| 57 |
|
|
|
| 58 |
|
|
$w->show_all; |
| 59 |
|
|
$brd->show_all; |
| 60 |
|
|
|
| 61 |
|
|
Gtk2->main; |