Skip to content

Commit

Permalink
do the computation
Browse files Browse the repository at this point in the history
  • Loading branch information
kenta2 committed May 3, 2016
1 parent 6a2c952 commit 99b13a1
Showing 1 changed file with 7 additions and 52 deletions.
59 changes: 7 additions & 52 deletions verify-filenames.pl
Original file line number Diff line number Diff line change
@@ -1,25 +1,12 @@
#! perl -wl
# Find nodes that were specified as part of an opening book, and not found by calculation.
# Verify that the filename of a log file matches the position evaluated in it.
use strict;
die unless defined(my$dir=$ARGV[0]);
die unless -d $dir;
my@logs;
for(<$dir/*.log>){
push @logs,$_;
}
my%seen;
my%parent;
my%store_moves;
my%store_fen;
for(my$i=0;$i<@logs;++$i){
my$fn=$logs[$i];
for my$fn(<$dir/*.log>){
my$canonical=&make_canonical($fn);
#print"$i $canonical";
if(defined$seen{canonical}){
print STDERR "duplicate $fn $seen{$fn}";
next;
}
$seen{$canonical}=$fn;
open FI,$fn or die "cannot open $fn";
my$moves;
die if defined$moves; #assuming undefined per scope
Expand All @@ -31,43 +18,11 @@
close FI;
die unless defined($moves);
$moves=~s/\s+$//;
$store_moves{$canonical}=$moves;
$store_fen{$moves}=$canonical;
}
for my$fn(@logs){
my$canonical=&make_canonical($fn);
open FI,"$dir/$canonical" or die;
my$bestmove;
die if defined($bestmove);
while(<FI>){
next if /bestmove\s+\(none\)/;
$bestmove=$1 if /bestmove\s+(\S+)/;
}
close FI;
unless(defined$bestmove){
print "skipping $canonical";
}else{
die unless defined(my$moves=$store_moves{$canonical});
my$query="$moves $bestmove";
$query =~ s/^ //;
my$child=$store_fen{"$query"};
if($child){
$parent{$child}.=" $child";
} else {
$child=`perl moves-to-fen.pl --fen $query`;
chomp$child;
die unless $child=~/^fen (\S+)$/;
$child=$1;
#print "Cannot find '$query'";
}
}
}
for my$fn(sort@logs){
my$canonical=&make_canonical($fn);
die unless defined($store_moves{$canonical});
unless(defined$parent{$canonical}){
print"$store_moves{$canonical} = $canonical";
}
my$fen=`perl moves-to-fen.pl --fen $moves`;
chomp$fen;
die unless $fen=~/^fen (\S+)$/;
$fen=$1;
print "mismatch $fn" unless $canonical eq $fen;
}
sub make_canonical{
my$canonical=shift;
Expand Down

0 comments on commit 99b13a1

Please sign in to comment.