Detect faulty tsumego
Below is a script to print a list of files in a directory where the final move is played by a different colour than the first move. This can be useful since some tsumego collections have problems which cannot be solved using some software (eg gogrinder)
use File::Slurp;
my $path = shift;
my @files = read_dir($path, prefix => 1);
for my $file (sort @files) {
print "$file\n" if comparefirstandlastmove(read_file($file));
}
sub comparefirstandlastmove {
my $sgf = shift; if ($sgf =~ /;([BW])\[/) { my $firstmove = $1; if ($sgf =~ /;([BW])\[..\]\)$/) { my $lastmove = $1; return 1 if $firstmove ne $lastmove } } return 0
}