Page 1 of 1

ngf

Posted: Sun Feb 27, 2011 10:07 am
by LovroKlc
How can I change .ngf files to .sgf? I get the ngf's when I look at my wbaduk gibo.

Re: ngf

Posted: Sun Feb 27, 2011 11:39 am
by SpongeBob
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.

Re: ngf

Posted: Sun Feb 27, 2011 12:46 pm
by Jordus
Multigo does for sure.... Not sure about drago...

Re: ngf

Posted: Mon Feb 28, 2011 2:34 pm
by LovroKlc
thanks, I will try that programs.

Re: ngf

Posted: Sun May 22, 2011 1:55 am
by toadwarble
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.

Re: ngf

Posted: Sun May 22, 2011 2:06 am
by parliament
If it's just a short script you can attach it directly...or am I wrong?

Re: ngf

Posted: Mon May 23, 2011 5:51 am
by toadwarble
#! /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";