ngf
- SpongeBob
- Lives in gote
- Posts: 499
- Joined: Sat Apr 24, 2010 3:18 pm
- Rank: Fox 3D
- GD Posts: 325
- Location: Germany
- Has thanked: 213 times
- Been thanked: 96 times
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.
You can check other programs like Drago and MultiGo, maybe they are capable of that, too.
Stay out of my territory! (W. White, aka Heisenberg)
- toadwarble
- Beginner
- Posts: 11
- Joined: Mon Jan 17, 2011 2:04 am
- Rank: BGA 9K
- GD Posts: 0
- KGS: toadwarble
- Been thanked: 1 time
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.
It needs to learn how to put down handicap stones, especially 3.
John Collins
-
parliament
- Dies in gote
- Posts: 49
- Joined: Fri Apr 15, 2011 9:45 pm
- GD Posts: 0
- Has thanked: 1 time
- toadwarble
- Beginner
- Posts: 11
- Joined: Mon Jan 17, 2011 2:04 am
- Rank: BGA 9K
- GD Posts: 0
- KGS: toadwarble
- Been thanked: 1 time
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";
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";
John Collins