From: Steinar H. Gunderson Date: Thu, 5 Sep 2019 20:23:12 +0000 (+0200) Subject: Fix a castling edge case in Chess960 positions where the kings start on the e-file... X-Git-Url: https://git.sesse.net/?p=remoteglot;a=commitdiff_plain;h=fae57f5f7ea4fee8a25c506b6c04f67c49833350 Fix a castling edge case in Chess960 positions where the kings start on the e-file and the rooks on c- or g-files. --- diff --git a/Board.pm b/Board.pm index 8565c84..6fb413a 100644 --- a/Board.pm +++ b/Board.pm @@ -44,8 +44,8 @@ sub make_move { if ($piece eq 'K') { # Convert to Chess960 king-takes-rook. - $to_col = 7 if ($move eq 'e1g1'); - $to_col = 0 if ($move eq 'e1c1'); + $to_col = 7 if ($move eq 'e1g1' && $board->[$to_row][$to_col] ne 'R'); + $to_col = 0 if ($move eq 'e1c1' && $board->[$to_row][$to_col] ne 'R'); my $dst_piece = $board->[$to_row][$to_col]; @@ -71,8 +71,8 @@ sub make_move { } } elsif ($piece eq 'k') { # Convert to Chess960 king-takes-rook. - $to_col = 7 if ($move eq 'e8g8'); - $to_col = 0 if ($move eq 'e8c8'); + $to_col = 7 if ($move eq 'e8g8' && $board->[$to_row][$to_col] ne 'r'); + $to_col = 0 if ($move eq 'e8c8' && $board->[$to_row][$to_col] ne 'r'); my $dst_piece = $board->[$to_row][$to_col];