Fix an issue where we would lose the history after Chess960-style castling, since...
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 26 Nov 2018 22:50:53 +0000 (23:50 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 26 Nov 2018 22:52:27 +0000 (23:52 +0100)
Position.pm

index 3e3e84f..3e39e46 100644 (file)
@@ -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;