}
if ($piece eq 'K') {
+ # Convert to Chess960 king-takes-rook.
+ $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];
- # 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] = '-';
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';
return $nb;
}
} elsif ($piece eq 'k') {
+ # Convert to Chess960 king-takes-rook.
+ $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];
- # 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';
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] = '-';