Fix various Chess960 castling bugs.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 6 Jan 2018 21:56:18 +0000 (22:56 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 6 Jan 2018 21:56:18 +0000 (22:56 +0100)
Board.pm

index 783aef0..579adbd 100644 (file)
--- a/Board.pm
+++ b/Board.pm
@@ -46,26 +46,21 @@ sub make_move {
                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') {
+               if ($move eq 'e1g1' || ($dst_piece eq 'R' && $to_col > $from_col)) {
                        # king
                        $nb->[7][$from_col] = '-';
-                       $nb->[7][6] = $piece;
-
-                       # rook
                        $nb->[7][$to_col] = '-';
+                       $nb->[7][6] = 'K';
                        $nb->[7][5] = 'R';
 
                        return $nb;
                }
 
                # White long castling (regular or Chess960 king-takes-rook)
-               if ($move eq 'e1c1' || $dst_piece eq 'R') {
-                       # king
+               if ($move eq 'e1c1' || ($dst_piece eq 'R' && $to_col < $from_col)) {
                        $nb->[7][$from_col] = '-';
-                       $nb->[7][2] = $piece;
-
-                       # rook
                        $nb->[7][$to_col] = '-';
+                       $nb->[7][2] = 'K';
                        $nb->[7][3] = 'R';
 
                        return $nb;
@@ -74,26 +69,21 @@ sub make_move {
                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') {
-                       # king
-                       $nb->[0][$from_col] = '-';
-                       $nb->[0][6] = $piece;
-
-                       # rook
+               if ($move eq 'e8g8' || ($dst_piece eq 'r' && $to_col > $from_col)) {
                        $nb->[0][$from_col] = '-';
+                       $nb->[0][$to_col] = '-';
+                       $nb->[0][6] = 'k';
                        $nb->[0][5] = 'r';
 
                        return $nb;
                }
 
                # black long castling
-               if ($move eq 'e8c8' || $dst_piece eq 'r') {
+               if ($move eq 'e8c8' || ($dst_piece eq 'r' && $to_col < $from_col)) {
                        # king
                        $nb->[0][$from_col] = '-';
-                       $nb->[0][2] = $piece;
-
-                       # rook
                        $nb->[0][$to_col] = '-';
+                       $nb->[0][2] = 'k';
                        $nb->[0][3] = 'r';
 
                        return $nb;