Allow entry of shogi promotions in any variant
authorH.G.Muller <hgm@hgm-xboard.(none)>
Thu, 28 May 2020 20:41:24 +0000 (22:41 +0200)
committerH.G.Muller <hgm@hgm-xboard.(none)>
Thu, 28 May 2020 20:41:24 +0000 (22:41 +0200)
Defining pieces as shogi-promotion partners did not cause triggering
of the promotion procedure when the corresponding basic piece reached
the zone for variants other than (Chu) Shogi. Now HasPromotionChoice()
recognizes pieces with a partner with ID '+' as promoting in any variant.
In variant fairy promotion on leaving the zone is now suppressed.
(This used to be only the case in variant elven.) This allows two-stage
promotions, where a Pawn first promote to a basic piece, and after leaving
the zone, the basic piece can promote again to its fixed partner.
(Like in Chess and a Half.)

backend.c

index 048fd0a..5ad3e36 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -6757,6 +6757,7 @@ HasPromotionChoice (int fromX, int fromY, int toX, int toY, char *promoChoice, i
     if(legal[toY][toX] == 4) return FALSE;
 
     piece = boards[currentMove][fromY][fromX];
+    if(PieceToChar(CHUPROMOTED(piece)) == '+') highestPromotingPiece = WhiteKing; // always obey PTC table
     if(gameInfo.variant == VariantChu) {
         promotionZoneSize = (BOARD_HEIGHT - deadRanks)/3;
         if(legal[toY][toX] == 6) return FALSE; // no promotion if highlights deny it
@@ -6779,12 +6780,13 @@ HasPromotionChoice (int fromX, int fromY, int toX, int toY, char *promoChoice, i
     if((int)piece >= BlackPawn) {
         if(toY >= promotionZoneSize && fromY >= promotionZoneSize)
              return FALSE;
-        if(fromY < promotionZoneSize && gameInfo.variant == VariantChuChess) return FALSE;
+        if(fromY < promotionZoneSize && (gameInfo.variant == VariantChuChess || gameInfo.variant == VariantFairy)) return FALSE;
         highestPromotingPiece = WHITE_TO_BLACK highestPromotingPiece;
     } else {
         if(  toY < BOARD_HEIGHT - deadRanks - promotionZoneSize &&
            fromY < BOARD_HEIGHT - deadRanks - promotionZoneSize) return FALSE;
-        if(fromY >= BOARD_HEIGHT - deadRanks - promotionZoneSize && gameInfo.variant == VariantChuChess)
+        if(fromY >= BOARD_HEIGHT - deadRanks - promotionZoneSize &&
+           (gameInfo.variant == VariantChuChess || gameInfo.variant == VariantFairy))
              return FALSE;
     }