set castling rights after setting up a position
authorH.G. Muller <h.g.muller@hccnet.nl>
Sat, 5 Sep 2009 05:39:45 +0000 (22:39 -0700)
committerArun Persaud <arun@nubati.net>
Sat, 5 Sep 2009 05:39:45 +0000 (22:39 -0700)
I was going through old WB forum posts, and I encountered a
bug report for a bug that I never fixed: The castling rights should
be properly set (actually: cleared) after setting up a position
in Edit Position mode (as opposed to pasting a FEN).

backend.c

index b0d9351..90021ce 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -10912,8 +10912,19 @@ ExitAnalyzeMode()
 void
 EditPositionDone()
 {
+    int king = gameInfo.variant == VariantKnightmate ? WhiteUnicorn : WhiteKing;
+
     startedFromSetupPosition = TRUE;
     InitChessProgram(&first, FALSE);
+    castlingRights[0][2] = castlingRights[0][5] = BOARD_WIDTH>>1;
+    if(boards[0][0][BOARD_WIDTH>>1] == king) {
+       castlingRights[0][1] = boards[0][0][BOARD_LEFT] == WhiteRook ? 0 : -1;
+       castlingRights[0][0] = boards[0][0][BOARD_RGHT-1] == WhiteRook ? BOARD_RGHT-1 : -1;
+    } else castlingRights[0][2] = -1;
+    if(boards[0][BOARD_HEIGHT-1][BOARD_WIDTH>>1] == WHITE_TO_BLACK king) {
+       castlingRights[0][4] = boards[0][BOARD_HEIGHT-1][BOARD_LEFT] == BlackRook ? 0 : -1;
+       castlingRights[0][3] = boards[0][BOARD_HEIGHT-1][BOARD_RGHT-1] == BlackRook ? BOARD_RGHT-1 : -1;
+    } else castlingRights[0][5] = -1;
     SendToProgram("force\n", &first);
     if (blackPlaysFirst) {
        strcpy(moveList[0], "");