Fix TwoKings ICS castling-rights bug
authorH.G. Muller <h.g.muller@hccnet.nl>
Wed, 13 Jan 2010 10:35:34 +0000 (11:35 +0100)
committerArun Persaud <arun@nubati.net>
Thu, 14 Jan 2010 05:08:04 +0000 (21:08 -0800)
Scanning the rank (as is done because of FRC) assigned castling rights
to the rightmost King. Even scanning the opposite direction would not
work, as it is not always the leftmost King that can castle. So we now
explicitly test for a King on e1/e8 in TwoKings and assign it rights,
relying on the Rook rights received from the ICS to control castling.

backend.c

index 31427c3..571ff13 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -3700,6 +3700,11 @@ ParseBoard12(string)
         for(k=BOARD_LEFT; k<BOARD_RGHT; k++)
             if(board[BOARD_HEIGHT-1][k] == bKing)
                 initialRights[5] = castlingRights[moveNum][5] = k;
+        if(gameInfo.variant == VariantTwoKings) {
+            // In TwoKings looking for a King does not work, so always give castling rights to a King on e1/e8
+            if(board[0][4] == wKing) initialRights[2] = castlingRights[moveNum][2] = 4;
+            if(board[BOARD_HEIGHT-1][4] == bKing) initialRights[5] = castlingRights[moveNum][5] = 4;
+        }
     } else { int r;
         r = castlingRights[moveNum][0] = initialRights[0];
         if(board[0][r] != WhiteRook) castlingRights[moveNum][0] = -1;