Remeber last-moved piece in only one Board square
authorH.G.Muller <hgm@hgm-xboard.(none)>
Mon, 5 Dec 2016 10:15:48 +0000 (11:15 +0100)
committerH.G.Muller <hgm@hgm-xboard.(none)>
Fri, 13 Jan 2017 15:39:25 +0000 (16:39 +0100)
The amount of game-state data (castling rights, e.p. state...) carried
along in the extra rank above the real board is getting a bit out of hand.
Rather than storing rank and file of the last-moved piece in two separate
off-board squares in that rank, we now combine them into a single number
(which would still allow boards of upto 64 files).

backend.c
common.h
moves.c

index 890461a..ff0608b 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -10220,9 +10220,9 @@ ApplyMove (int fromX, int fromY, int toX, int toY, int promoChar, Board board)
     /* we can always do that 'in place', now pointers to these rights are passed to ApplyMove */
 
       if(gameInfo.variant == VariantBerolina) berolina = EP_BEROLIN_A;
-      oldEP = (signed char)board[EP_STATUS]; epRank = board[EP_RANK]; epFile = board[EP_FILE]; lastFile = board[LAST_FILE],lastRank = board[LAST_RANK];
+      oldEP = (signed char)board[EP_STATUS]; epRank = board[EP_RANK]; epFile = board[EP_FILE]; lastFile = board[LAST_TO] & 255,lastRank = board[LAST_TO] >> 8;
       board[EP_STATUS] = EP_NONE;
-      board[EP_FILE] = board[EP_RANK] = board[LAST_FILE] = board[LAST_RANK] = 100;
+      board[EP_FILE] = board[EP_RANK] = 100, board[LAST_TO] = 0x4040;
 
   if (fromY == DROP_RANK) {
        /* must be first */
@@ -10278,7 +10278,7 @@ ApplyMove (int fromX, int fromY, int toX, int toY, int promoChar, Board board)
                if(toX<BOARD_RGHT-1 && board[toY][toX+1] == BlackPawn &&
                        gameInfo.variant != VariantBerolina || toX > fromX)
                      board[EP_STATUS] = toX;
-              board[LAST_FILE] = toX; board[LAST_RANK] = toY;
+              board[LAST_TO] = toX + 256*toY;
           }
       } else
       if( pawn == BlackPawn ) {
@@ -10292,7 +10292,7 @@ ApplyMove (int fromX, int fromY, int toX, int toY, int promoChar, Board board)
                if(toX<BOARD_RGHT-1 && board[toY][toX+1] == WhitePawn &&
                        gameInfo.variant != VariantBerolina || toX > fromX)
                      board[EP_STATUS] = toX;
-              board[LAST_FILE] = toX; board[LAST_RANK] = toY;
+              board[LAST_TO] = toX + 256*toY;
           }
        }
 
index b1b239c..7e74e06 100644 (file)
--- a/common.h
+++ b/common.h
@@ -181,8 +181,7 @@ typedef char *String;
 #define BOARD_RGHT   (gameInfo.boardWidth + gameInfo.holdingsWidth)
 #define CASTLING     (BOARD_RANKS-1)           /* [HGM] hide in upper rank   */
 #define VIRGIN       (BOARD_RANKS-2)           /* [HGM] pieces not moved     */
-#define LAST_RANK    CASTLING][(BOARD_FILES-8) /* [HGM] in upper rank        */
-#define LAST_FILE    CASTLING][(BOARD_FILES-7) /* [HGM] in upper rank        */
+#define LAST_TO      CASTLING][(BOARD_FILES-7) /* [HGM] in upper rank        */
 #define TOUCHED_W    CASTLING][(BOARD_FILES-6) /* [HGM] in upper rank        */
 #define TOUCHED_B    CASTLING][(BOARD_FILES-5) /* [HGM] in upper rank        */
 #define EP_RANK      CASTLING][(BOARD_FILES-4) /* [HGM] in upper rank        */
diff --git a/moves.c b/moves.c
index 30f94b5..ef2f504 100644 (file)
--- a/moves.c
+++ b/moves.c
@@ -809,7 +809,7 @@ GenPseudoLegal (Board board, int flags, MoveCallback callback, VOIDSTAR closure,
                               rf, ff, rf + 1, ff + s, closure);
                  }
                  if (rf >= BOARD_HEIGHT+1>>1) {// [HGM] grand: 4th & 5th rank on 10-board
-                     int victimFile = (board[LAST_FILE] == 100 ? ff + s : board[LAST_FILE]);
+                     int victimFile = (board[LAST_TO] & 0x40 ? ff + s : board[LAST_TO] & 255);
                       if (ff + s >= BOARD_LEFT && ff + s < BOARD_RGHT &&
                          (board[EP_FILE] == ff + s || epfile == EP_UNKNOWN) && rf < BOARD_HEIGHT-3 &&
                           (board[rf][victimFile] == BlackPawn || board[rf][victimFile] == BlackLance) &&
@@ -860,7 +860,7 @@ GenPseudoLegal (Board board, int flags, MoveCallback callback, VOIDSTAR closure,
                               rf, ff, rf - 1, ff + s, closure);
                  }
                  if (rf < BOARD_HEIGHT>>1) {
-                     int victimFile = (board[LAST_FILE] == 100 ? ff + s : board[LAST_FILE]);
+                     int victimFile = (board[LAST_TO] & 0x40 ? ff + s : board[LAST_TO] & 255);
                       if (ff + s >= BOARD_LEFT && ff + s < BOARD_RGHT &&
                          (board[EP_FILE] == ff + s || epfile == EP_UNKNOWN) && rf > 2 &&
                          (board[rf][victimFile] == WhitePawn || board[rf][victimFile] == WhiteLance) &&