X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=Board.pm;h=91d1a15f7f42b29d5057c2cb9205ae4874a52361;hb=1c8fd12582bf90b4cb31a4bdf6a82bbdd939acb4;hp=921de3d9c45f715e7084796aeb1a005bc5270093;hpb=cd07e136301429ab1f50027c78a9188799f1c9ae;p=remoteglot diff --git a/Board.pm b/Board.pm index 921de3d..91d1a15 100644 --- a/Board.pm +++ b/Board.pm @@ -177,23 +177,26 @@ sub parse_pretty_move { } $move =~ /^([KQRBN])?([a-h])?([1-8])?x?([a-h][1-8])$/ or die "Invalid move $move"; - my $piece = $1 // 'P'; + my $piece = $1; my $from_col = defined($2) ? _col_letter_to_num($2) : undef; my $from_row = defined($3) ? _row_letter_to_num($3) : undef; + if (!defined($piece) && (!defined($from_col) || !defined($from_row))) { + $piece = 'P'; + } my ($to_row, $to_col) = _square_to_pos($4); # Find all possible from-squares that could have been meant. my @squares = (); my $side = 'K'; if ($toplay eq 'B') { - $piece = lc($piece); + $piece = lc($piece) if defined($piece); $side = 'k'; } for my $row (0..7) { next if (defined($from_row) && $from_row != $row); for my $col (0..7) { next if (defined($from_col) && $from_col != $col); - next if ($board->[$row][$col] ne $piece); + next if (defined($piece) && $board->[$row][$col] ne $piece); push @squares, [ $row, $col ]; } }