From c550c243e90e48b901f25cd0a609cfd6b8f2e326 Mon Sep 17 00:00:00 2001 From: H.G. Muller Date: Mon, 3 Jan 2011 12:08:19 +0100 Subject: [PATCH] Fix promotion of Pawn-like Lance In variants where the Lance is used to represent an unorthodox Pawn, it must promote when it reaches last rank. With legality testing on, however, the promoChar was ignored in ApplyMove in this case. The promotion suffix also was not appended in SAN moves. --- backend.c | 14 ++++++++++---- moves.c | 5 +++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/backend.c b/backend.c index e686722..dc2972c 100644 --- a/backend.c +++ b/backend.c @@ -5668,6 +5668,12 @@ HasPromotionChoice(int fromX, int fromY, int toX, int toY, char *promoChoice) promotionZoneSize = 3; } + // Treat Lance as Pawn when it is not representing Amazon + if(gameInfo.variant != VariantSuper) { + if(piece == WhiteLance) piece = WhitePawn; else + if(piece == BlackLance) piece = BlackPawn; + } + // next weed out all moves that do not touch the promotion zone at all if((int)piece >= BlackPawn) { if(toY >= promotionZoneSize && fromY >= promotionZoneSize) @@ -8482,9 +8488,9 @@ ApplyMove(fromX, fromY, toX, toY, promoChar, board) board[toY][toX] = king; board[toY][toX+1] = board[fromY][BOARD_LEFT]; board[fromY][BOARD_LEFT] = EmptySquare; - } else if (board[fromY][fromX] == WhitePawn + } else if ((board[fromY][fromX] == WhitePawn && gameInfo.variant != VariantXiangqi || + board[fromY][fromX] == WhiteLance && gameInfo.variant != VariantSuper && gameInfo.variant != VariantShogi) && toY >= BOARD_HEIGHT-promoRank - && gameInfo.variant != VariantXiangqi ) { /* white pawn promotion */ board[toY][toX] = CharToPiece(ToUpper(promoChar)); @@ -8546,9 +8552,9 @@ ApplyMove(fromX, fromY, toX, toY, promoChar, board) board[toY][toX] = BlackKing; board[fromY][0] = EmptySquare; board[toY][2] = BlackRook; - } else if (board[fromY][fromX] == BlackPawn + } else if ((board[fromY][fromX] == BlackPawn && gameInfo.variant != VariantXiangqi || + board[fromY][fromX] == BlackLance && gameInfo.variant != VariantSuper && gameInfo.variant != VariantShogi) && toY < promoRank - && gameInfo.variant != VariantXiangqi ) { /* black pawn promotion */ board[toY][toX] = CharToPiece(ToLower(promoChar)); diff --git a/moves.c b/moves.c index 6ccbb1c..d8768f4 100644 --- a/moves.c +++ b/moves.c @@ -1604,6 +1604,11 @@ ChessMove CoordsToAlgebraic(board, flags, rf, ff, rt, ft, promoChar, out) /* [HGM] in Shogi non-pawns can promote */ *outp++ = promoChar; // Don't bother to correct move type, return value is never used! } + else if (gameInfo.variant != VariantSuper && promoChar && + (piece == WhiteLance || piece == BlackLance) ) { // Lance sometimes represents Pawn + *outp++ = '='; + *outp++ = ToUpper(promoChar); + } else if (gameInfo.variant == VariantSChess && promoChar) { // and in S-Chess we have gating *outp++ = '/'; *outp++ = ToUpper(promoChar); -- 1.7.0.4