X-Git-Url: https://git.sesse.net/?p=remoteglot;a=blobdiff_plain;f=Position.pm;h=3e39e46f0f09ed2d762b6e3f3eca002b800e974b;hp=8cfc4a6e8c6caac1b3d02d33c25ce27cc07b75cd;hb=e961331f0f08ba475f53599442c0d330bd520c91;hpb=10ac7d58489ba6f8fcc340dbe5c90e0bc41e21fb diff --git a/Position.pm b/Position.pm index 8cfc4a6..3e39e46 100644 --- a/Position.pm +++ b/Position.pm @@ -74,7 +74,7 @@ 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 = _col_num_to_letter(_find_piece_col($board->[7], 'K')); if ($rook_col lt $king_col) { @@ -89,7 +89,7 @@ sub from_fen { 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 = _col_num_to_letter(_find_piece_col($board->[0], 'k')); if ($rook_col lt $king_col) { @@ -275,8 +275,11 @@ sub make_move { $np->{'black_castle_k'} = undef; } - # 50-move rule. - if (lc($piece) eq 'p' || $dest_piece ne '-') { + # 50-move rule. Note that castle does not reset the counter, per FIDE rules. + my $castling = (lc($piece) eq 'k' && abs($from_col - $to_col) > 1) || # King moves two squares. + ($piece eq 'K' && $dest_piece eq 'R') || # Chess960-style king-takes-rook. + ($piece eq 'k' && $dest_piece eq 'r'); + if (!$castling && (lc($piece) eq 'p' || $dest_piece ne '-')) { $np->{'time_since_100move_rule_reset'} = 0; } else { $np->{'time_since_100move_rule_reset'} = $pos->{'time_since_100move_rule_reset'} + 1;