]> git.sesse.net Git - remoteglot/blobdiff - Board.pm
Deal with inconsistent zero padding in PGN clocks.
[remoteglot] / Board.pm
index 655b7f1bbb70a43ff56be1a3f17cdc26524aa8b3..39c8134096b5897a0e7bd0ff47baad0441fe310f 100644 (file)
--- a/Board.pm
+++ b/Board.pm
@@ -200,8 +200,11 @@ sub parse_pretty_move {
                        push @squares, [ $row, $col ];
                }
        }
+       if (scalar @squares == 0) {
+               die "Impossible move $move";
+       }
        if (scalar @squares != 1) {
-               die "Ambigious or impossible move $move";
+               die "Ambigious move $move";
        }
        return (@{$squares[0]}, $to_row, $to_col, $promo);
 }
@@ -425,6 +428,19 @@ sub prettyprint_move {
        return ($pretty, $nb);
 }
 
+sub num_pieces {
+       my ($board) = @_;
+
+       my $num = 0;
+       for my $row (0..7) {
+               for my $col (0..7) {
+                       my $piece = $board->[$row][$col];
+                       ++$num if ($piece ne '-');
+               }
+       }
+       return $num;    
+}
+
 sub _prettyprint_move_no_check_or_mate {
         my ($board, $from_row, $from_col, $to_row, $to_col, $promo) = @_;
        my $piece = $board->[$from_row][$from_col];