trying to use Games::Go::SGF

D

doolittle

Hi,

My code stops (with Can't call method "move" on unblessed reference)
when i try to access the methods of a variation object. The first (non
variation) move is shown OK ('2:pd' in the output), and when i do
'print Dumper($var);', that kinda looks like its the right sort of
thing, but i can't do anything with it.

Code:

use strict;
use warnings;
use Games::Go::SGF;
use Data::Dumper;

my $sgf = new
Games::Go::SGF('(;GM[1]FF[4]SZ[19];B[pd](;W[pp])(;W[cf]))');

print Dumper($sgf);

my $move_no = 1;
while (my $walker = $sgf->move($move_no++)) {

if (ref($walker) eq 'Games::Go::SGF::Node'){
print "$move_no: ".$walker->move,"\n";
}
if (ref($walker) eq 'Games::Go::SGF::Variation'){
my $var = $walker->variation(0);
print Dumper($var);
my $varwalker = $var->move(1); # fails here
print '1: '.$varwalker->move,"\n";
}

}

This prints out:

Can't call method "move" on unblessed reference at go2.pl line 19.
(in cleanup) Can't use string ("Games::Go::SGF::Node::DESTROY") as a
subroutine ref while "strict refs" in use at
C:/Perl/site/lib/Games/Go/SGF.pm line 83.
$VAR1 = bless( [
bless( {
'next' => bless( {
'next' => bless( [
[

bless( {

'next' => undef,

'W' => 'pp',

'moves_to_first_variation' => 0

}, 'Games::Go::SGF::Node' ),
{

'next' => undef
}
],
[

bless( {

'next' => undef,

'W' => 'cf',

'moves_to_first_variation' => 0

}, 'Games::Go::SGF::Node' ),
{

'next' => undef
}
]
],
'Games::Go::SGF::Variation' ),
'B' => 'pd'
}, 'Games::Go::SGF::Node' ),
'FF' => '4',
'moves_to_first_variation' => 2,
'GM' => '1',
'SZ' => '19'
}, 'Games::Go::SGF::Node' ),
$VAR1->[0]{'next'},
$VAR1->[0]{'next'}{'next'},
{
'next' => undef
}
], 'Games::Go::SGF' );
2: pd
$VAR1 = [
bless( {
'next' => undef,
'W' => 'pp',
'moves_to_first_variation' => 0
}, 'Games::Go::SGF::Node' ),
{
'next' => undef
}
];
 
D

doolittle

The following code shows a workaround. Does anybody know how to change
the Games::Go::SGF module so this is unneccessary?

use Games::Go::SGF;

my $sgf = new Games::Go::SGF('(;GM[1]FF[4]SZ[19];B[pd](;W[cf]))');

my $move_no = 1;
while (my $walker = $sgf->move($move_no++)) {
if (ref($walker) eq 'Games::Go::SGF::Variation'){
my $var = $walker->variation(0);
#uncomment the next line to show unexpected behaviour (bug?)
# print $var->move,"\n";
print ref($var),"\n"; # this is an ARRAY
my @deref = @{$var};
print ref($deref[0]),"\n";
print 'var move '."$move_no: ".$deref[0]->move,"\n";
}
}

prints out:

ARRAY
Games::Go::SGF::Node
var move 3: cf

A similar problem happens with the 'variations' method,which returns an
array of arrays rather than the expected array of Nodes.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,785
Messages
2,569,624
Members
45,319
Latest member
LorenFlann

Latest Threads

Top