From: Steinar H. Gunderson Date: Sat, 13 Jan 2018 13:29:21 +0000 (+0100) Subject: Fix non-Chess960 castling. X-Git-Url: https://git.sesse.net/?p=remoteglot;a=commitdiff_plain;h=137fd252df56a42eac5ba1ad7d251b633846ed4f;hp=6dd4f0d4b11f86cc8490bbb0462259232fa80a7a Fix non-Chess960 castling. --- diff --git a/Board.pm b/Board.pm index 579adbd..8565c84 100644 --- a/Board.pm +++ b/Board.pm @@ -43,10 +43,14 @@ 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'); + my $dst_piece = $board->[$to_row][$to_col]; - # White short castling (regular or Chess960 king-takes-rook) - if ($move eq 'e1g1' || ($dst_piece eq 'R' && $to_col > $from_col)) { + # White short castling. + if ($dst_piece eq 'R' && $to_col > $from_col) { # king $nb->[7][$from_col] = '-'; $nb->[7][$to_col] = '-'; @@ -56,8 +60,8 @@ sub make_move { return $nb; } - # White long castling (regular or Chess960 king-takes-rook) - if ($move eq 'e1c1' || ($dst_piece eq 'R' && $to_col < $from_col)) { + # Black short castling. + if ($dst_piece eq 'R' && $to_col < $from_col) { $nb->[7][$from_col] = '-'; $nb->[7][$to_col] = '-'; $nb->[7][2] = 'K'; @@ -66,10 +70,14 @@ sub make_move { return $nb; } } elsif ($piece eq 'k') { + # Convert to Chess960 king-takes-rook. + $to_col = 7 if ($move eq 'e8g8'); + $to_col = 0 if ($move eq 'e8c8'); + my $dst_piece = $board->[$to_row][$to_col]; - # Black short castling (regular or Chess960 king-takes-rook) - if ($move eq 'e8g8' || ($dst_piece eq 'r' && $to_col > $from_col)) { + # Black short castling. + if ($dst_piece eq 'r' && $to_col > $from_col) { $nb->[0][$from_col] = '-'; $nb->[0][$to_col] = '-'; $nb->[0][6] = 'k'; @@ -78,8 +86,8 @@ sub make_move { return $nb; } - # black long castling - if ($move eq 'e8c8' || ($dst_piece eq 'r' && $to_col < $from_col)) { + # Black long castling. + if ($dst_piece eq 'r' && $to_col < $from_col) { # king $nb->[0][$from_col] = '-'; $nb->[0][$to_col] = '-';