From fae57f5f7ea4fee8a25c506b6c04f67c49833350 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Thu, 5 Sep 2019 22:23:12 +0200 Subject: [PATCH 1/1] Fix a castling edge case in Chess960 positions where the kings start on the e-file and the rooks on c- or g-files. --- Board.pm | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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]; -- 2.39.2