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:49 +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 eftmost 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 937ba59..204cd44 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -3724,6 +3724,11 @@ ParseBoard12(string)
         for(k=BOARD_LEFT; k<BOARD_RGHT; k++)
             if(board[BOARD_HEIGHT-1][k] == bKing)
                 initialRights[5] = boards[moveNum][CASTLING][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] = boards[moveNum][CASTLING][2] = 4;
+            if(board[BOARD_HEIGHT-1][4] == bKing) initialRights[5] = boards[moveNum][CASTLING][5] = 4;
+        }
     } else { int r;
         r = boards[moveNum][CASTLING][0] = initialRights[0];
         if(board[0][r] != WhiteRook) boards[moveNum][CASTLING][0] = NoRights;