From 00f49d137feed871220bb1ed4193f86704d20dbf Mon Sep 17 00:00:00 2001 From: H.G.Muller Date: Sun, 2 Nov 2014 11:29:31 +0100 Subject: [PATCH] Allow e.p. capture on triple-Push Some variants (like Omega Chess) have an initial triple-Push on Pawns, wich can then e.p.-captured on both of the squares they skip. To allow the Betza move generator to supply such e.p. captures, a bit flag is kludged into the EP_RANK state indicator on triple pushes, while the main value there is that of the rank directly behind the pushed Pawn. The Betza generator then also matches the square behind it with the e.p.-capture to-square when the falg is set. ApplyMove() also had to be adapted, to remove the Pawn two squares behind the capturing one, rather than straight behind it, when this flag is set. --- backend.c | 20 ++++++++++++-------- moves.c | 5 +++-- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/backend.c b/backend.c index cb564b4..2c7933e 100644 --- a/backend.c +++ b/backend.c @@ -9932,8 +9932,8 @@ ApplyMove (int fromX, int fromY, int toX, int toY, int promoChar, Board board) if( board[fromY][fromX] == WhitePawn ) { if(fromY != toY) // [HGM] Xiangqi sideway Pawn moves should not count as 50-move breakers board[EP_STATUS] = EP_PAWN_MOVE; - if( toY-fromY==2) { - board[EP_FILE] = (fromX + toX)/2; board[EP_RANK] = (fromY + toY)/2; + if( toY-fromY>=2) { + board[EP_FILE] = (fromX + toX)/2; board[EP_RANK] = toY - 1 | 128*(toY - fromY > 2); if(toX>BOARD_LEFT && board[toY][toX-1] == BlackPawn && gameInfo.variant != VariantBerolina || toX < fromX) board[EP_STATUS] = toX | berolina; @@ -9945,8 +9945,8 @@ ApplyMove (int fromX, int fromY, int toX, int toY, int promoChar, Board board) if( board[fromY][fromX] == BlackPawn ) { if(fromY != toY) // [HGM] Xiangqi sideway Pawn moves should not count as 50-move breakers board[EP_STATUS] = EP_PAWN_MOVE; - if( toY-fromY== -2) { - board[EP_FILE] = (fromX + toX)/2; board[EP_RANK] = (fromY + toY)/2; + if( toY-fromY<= -2) { + board[EP_FILE] = (fromX + toX)/2; board[EP_RANK] = toY + 1 | 128*(fromY - toY > 2); if(toX>BOARD_LEFT && board[toY][toX-1] == WhitePawn && gameInfo.variant != VariantBerolina || toX < fromX) board[EP_STATUS] = toX | berolina; @@ -10039,8 +10039,10 @@ ApplyMove (int fromX, int fromY, int toX, int toY, int promoChar, Board board) && (board[toY][toX] == EmptySquare)) { board[fromY][fromX] = EmptySquare; board[toY][toX] = WhitePawn; - captured = board[toY - 1][toX]; - board[toY - 1][toX] = EmptySquare; + if(toY == board[EP_RANK] - 128 + 1) + captured = board[toY - 2][toX], board[toY - 2][toX] = EmptySquare; + else + captured = board[toY - 1][toX], board[toY - 1][toX] = EmptySquare; } else if ((fromY == BOARD_HEIGHT-4) && (toX == fromX) && gameInfo.variant == VariantBerolina @@ -10102,8 +10104,10 @@ ApplyMove (int fromX, int fromY, int toX, int toY, int promoChar, Board board) && (board[toY][toX] == EmptySquare)) { board[fromY][fromX] = EmptySquare; board[toY][toX] = BlackPawn; - captured = board[toY + 1][toX]; - board[toY + 1][toX] = EmptySquare; + if(toY == board[EP_RANK] - 128 - 1) + captured = board[toY + 2][toX], board[toY + 2][toX] = EmptySquare; + else + captured = board[toY + 1][toX], board[toY + 1][toX] = EmptySquare; } else if ((fromY == 3) && (toX == fromX) && gameInfo.variant == VariantBerolina diff --git a/moves.c b/moves.c index fa9a8cc..b4edc45 100644 --- a/moves.c +++ b/moves.c @@ -265,7 +265,7 @@ void MovesFromString (Board board, int flags, int f, int r, int tx, int ty, int angle, char *desc, MoveCallback cb, VOIDSTAR cl) { char buf[80], *p = desc, *atom = NULL; - int mine, his, dir, bit, occup, i, promoRank = -1; + int mine, his, dir, bit, occup, i, ep, promoRank = -1; ChessMove promo= NormalMove; ChessSquare pc = board[r][f]; if(pc == DarkSquare) return; // this is not a piece, but a 'hole' in the board if(flags & F_WHITE_ON_MOVE) his = 2, mine = 1; else his = 1, mine = 2; @@ -426,7 +426,8 @@ MovesFromString (Board board, int flags, int f, int r, int tx, int ty, int angle continue; } if(hop & 32+64) { if(occup != 4) { if(hop & 64 && i != 1) i = 2; hop &= 31; } continue; } // hopper - if(mode & 8 && y == board[EP_RANK] && occup == 4 && board[EP_FILE] == x) { // to e.p. square + ep = board[EP_RANK]; + if(mode & 8 && occup == 4 && board[EP_FILE] == x && (y == (ep & 127) || y - vy == ep - 128)) { // to e.p. square (or 2nd e.p. square) cb(board, flags, mine == 1 ? WhiteCapturesEnPassant : BlackCapturesEnPassant, r, f, y, x, cl); } if(mode & 1024) { // castling -- 1.7.0.4