Life In 19x19
http://lifein19x19.com/

ngf
http://lifein19x19.com/viewtopic.php?f=34&t=3321
Page 1 of 1

Author:  LovroKlc [ Sun Feb 27, 2011 10:07 am ]
Post subject:  ngf

How can I change .ngf files to .sgf? I get the ngf's when I look at my wbaduk gibo.

Author:  SpongeBob [ Sun Feb 27, 2011 11:39 am ]
Post subject:  Re: ngf

Moyo Go Studio let's you open the files and save them as .SGF.

You can check other programs like Drago and MultiGo, maybe they are capable of that, too.

Author:  Jordus [ Sun Feb 27, 2011 12:46 pm ]
Post subject:  Re: ngf

Multigo does for sure.... Not sure about drago...

Author:  LovroKlc [ Mon Feb 28, 2011 2:34 pm ]
Post subject:  Re: ngf

thanks, I will try that programs.

Author:  toadwarble [ Sun May 22, 2011 1:55 am ]
Post subject:  Re: ngf

I did write a Perl NGF to SGF conversion program if anyone wants a copy please ask.

It needs to learn how to put down handicap stones, especially 3.

Author:  parliament [ Sun May 22, 2011 2:06 am ]
Post subject:  Re: ngf

If it's just a short script you can attach it directly...or am I wrong?

Author:  toadwarble [ Mon May 23, 2011 5:51 am ]
Post subject:  Re: ngf

#! /usr/bin/perl

sub readit {
$_ = <INF>;
s/\r?\n//;
}

$file = shift;
die "No source file given\n" unless $file;
die "Expecting NGF file\n" unless $file =~ /\.ngf/i;
die "Cannot open $file\n" unless open(INF, $file);

# Application and type

readit;

# Board size

readit;
die "Confused by board size $_\n" unless /\d+/;
$Boardsize = $_;

# White player and rank

readit;
($wp,$wr) = /^(.*\S)\s+(\d+[kd]\S*)/i;

# Black player and rank

readit;
($bp,$br) = /^(.*\S)\s+(\d+[kd]\S*)/i;

# Website name

readit;
$Website = $_;

# Handicap

readit;
$Hcap = $_;

# Unknown

readit;

# Komi (add 0.5)

readit;
$Komi = $_;
$Komi .= '.5';

# Date and time

readit;
($yr,$mn,$dy,$hr,$min) = /(\d\d\d\d)(\d\d)(\d\d)\s+\[(\d\d):(\d\d)\]/;
die "Confused by date $_\n" unless $yr;

$outfile = "Oro-$wp-v-$bp-$yr$mn$dy-$hr$min.sgf";
die "Cannot create output $outfile\n" unless open(OUTF, ">$outfile");
select OUTF;

# Unknown

readit;

# Result

readit;
$res = substr($_, 0, 1);
$res = $res eq "W"? "B": "W" if /loses/;
$res .= '+';
if (/resig/i) {
$res .= 'R';
}
elsif (/time/i) {
$res .= 'T';
}
elsif (/(\d+(\.5)?)/) {
$res .= $1;
}
else {
die "Confused by result format $_\n";
}

# Number of moves

readit;
$nmoves = $_;

$Aoff = ord('A');
$adj = ord('a') - $Aoff - 1;

print <<EOT;
(;GM[1]FF[4]AP[ngf2sgf]ST[1]
SZ[$Boardsize]HA[$Hcap]KM[$Komi]
PW[$wp]WR[$wr]PB[$bp]BR[$br]RE[$res]DT[$yr-$mn-$dy]PC[Oro]
EOT

while (<INF>) {
s/\r?\n//;
my ($m1,$m2,$pl,$c1,$c2) = /PM(.)(.)(.)(.)(.)/;
my $oc1 = ord($c1);
my $oc2 = ord($c2);
if ($oc1 <= $Aoff || $oc2 <= $Aoff) {
print ";${pl}[tt]\n";
}
else {
print ";$pl", "[", chr($oc1 + $adj), chr($oc2 + $adj), "]\n";
}
}
print ")\n";

Page 1 of 1 All times are UTC - 8 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/