Fix spurious promotion for redefined Pawns in Xiangqi
authorH.G.Muller <hgm@hgm-xboard.(none)>
Wed, 7 Oct 2020 21:20:14 +0000 (23:20 +0200)
committerH.G.Muller <hgm@hgm-xboard.(none)>
Wed, 7 Oct 2020 21:20:14 +0000 (23:20 +0200)
The Betza move generator, used for pieces with moves redefined by the
'piece' command, always generated Pawn moves to last rank as promotions.
In Xiangqi this had the undesired effect that promotion suffixes were
considered missing on such moves arriving as text, and a default promotion
to Queen was appended to them. Which made the Pawns disappear, as a Queen
normally does not participate in Xiangqi.
  Now the MovesFromString routine suppresses promotion in Xiangqi and
Janggi. It still doesn't pay attention to zone depth in other variants.

moves.c

diff --git a/moves.c b/moves.c
index bbb3b91..f60ec7a 100644 (file)
--- a/moves.c
+++ b/moves.c
@@ -321,8 +321,10 @@ MovesFromString (Board board, int flags, int f, int r, int tx, int ty, int angle
     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;
-    if(pc == WhitePawn || pc == WhiteLance) promo = WhitePromotion, promoRank = BOARD_HEIGHT-1; else
-    if(pc == BlackPawn || pc == BlackLance) promo = BlackPromotion, promoRank = 0;
+    if(gameInfo.variant != VariantXiangqi && gameInfo.variant != VariantJanggi) {
+       if(pc == WhitePawn || pc == WhiteLance) promo = WhitePromotion, promoRank = BOARD_HEIGHT-1; else
+       if(pc == BlackPawn || pc == BlackLance) promo = BlackPromotion, promoRank = 0;
+    }
     while(*p) {                  // more moves to go
        int expo = -1, dx, dy, x, y, mode, dirSet, ds2=0, retry=0, initial=0, jump=1, skip = 0, all = 0, put = 0, u = 0;
        char *cont = NULL, *q;