From 8c5702d5679cd14739806e3498f67f0fb6b5ef79 Mon Sep 17 00:00:00 2001 From: H.G.Muller Date: Mon, 5 Dec 2016 11:15:48 +0100 Subject: [PATCH 1/1] Remeber last-moved piece in only one Board square 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 | 8 ++++---- common.h | 3 +-- moves.c | 4 ++-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/backend.c b/backend.c index 890461a..ff0608b 100644 --- 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 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 fromX) board[EP_STATUS] = toX; - board[LAST_FILE] = toX; board[LAST_RANK] = toY; + board[LAST_TO] = toX + 256*toY; } } diff --git a/common.h b/common.h index b1b239c..7e74e06 100644 --- 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 --- 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) && -- 1.7.0.4