X-Git-Url: https://git.sesse.net/?p=remoteglot;a=blobdiff_plain;f=Position.pm;h=3e3e84fd3f0282d55878f1a47ca3d215277c0000;hp=cd0cc975ff5fad2e3ff176ec7da634d76f1002ab;hb=17c1ac08187cea6c69bd193f43a58bc984d9a5bc;hpb=3ba7d7aa2f94b7be3cc1d4b6b19f11cb390ae77f diff --git a/Position.pm b/Position.pm index cd0cc97..3e3e84f 100644 --- a/Position.pm +++ b/Position.pm @@ -74,28 +74,28 @@ sub from_fen { if ($castling =~ /Q/) { $pos->{'white_castle_q'} = _col_num_to_letter(_find_piece_col($board->[7], 'R')); } - while ($castling =~ s/([A-H])//g) { + while ($castling =~ s/([A-H])//) { my $rook_col = lc($1); - my $king_col = _find_piece_col($board->[7], 'K'); - if ($rook_col < $king_col) { - $pos->{'white_castle_q'} = _col_num_to_letter($rook_col); + my $king_col = _col_num_to_letter(_find_piece_col($board->[7], 'K')); + if ($rook_col lt $king_col) { + $pos->{'white_castle_q'} = $rook_col; } else { - $pos->{'white_castle_k'} = _col_num_to_letter($rook_col); + $pos->{'white_castle_k'} = $rook_col; } } if ($castling =~ /k/) { - $pos->{'white_castle_k'} = _col_num_to_letter(_find_piece_col_from_right($board->[0], 'r')); + $pos->{'black_castle_k'} = _col_num_to_letter(_find_piece_col_from_right($board->[0], 'r')); } if ($castling =~ /q/) { $pos->{'black_castle_q'} = _col_num_to_letter(_find_piece_col($board->[0], 'r')); } - while ($castling =~ s/([a-h])//g) { + while ($castling =~ s/([a-h])//) { my $rook_col = $1; - my $king_col = _find_piece_col($board->[0], 'k'); - if ($rook_col < $king_col) { - $pos->{'black_castle_q'} = _col_num_to_letter($rook_col); + my $king_col = _col_num_to_letter(_find_piece_col($board->[0], 'k')); + if ($rook_col lt $king_col) { + $pos->{'black_castle_q'} = $rook_col; } else { - $pos->{'black_castle_k'} = _col_num_to_letter($rook_col); + $pos->{'black_castle_k'} = $rook_col; } } $pos->{'time_since_100move_rule_reset'} = $halfmove_clock // 0;