From 6a2c95237d81ad78d02f1960b47d89a4fc47efa8 Mon Sep 17 00:00:00 2001 From: Ken T Takusagawa Date: Mon, 2 May 2016 21:55:59 -0400 Subject: [PATCH] copy of no-parents, to verify that the FEN filenames match the position being evaluated. --- verify-filenames.pl | 77 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 verify-filenames.pl diff --git a/verify-filenames.pl b/verify-filenames.pl new file mode 100644 index 0000000..d23db88 --- /dev/null +++ b/verify-filenames.pl @@ -0,0 +1,77 @@ +#! perl -wl +# Find nodes that were specified as part of an opening book, and not found by calculation. +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]; + 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 + + while(){ + chomp; + $moves=$1 if /^position startpos moves\s*(.*)/; + } + 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(){ + 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"; + } +} +sub make_canonical{ + my$canonical=shift; + $canonical=~s/\.\d+\.log//; + $canonical=~s!.*/!!; + $canonical +}