Handle Shogi promotions on SAN moves
authorH.G. Muller <h.g.muller@hccnet.nl>
Mon, 11 Oct 2010 06:57:39 +0000 (08:57 +0200)
committerH.G. Muller <h.g.muller@hccnet.nl>
Mon, 11 Oct 2010 06:57:39 +0000 (08:57 +0200)
lasker-2.2.3/src/algcheck.c

index 065a859..cdc97b2 100644 (file)
@@ -222,6 +222,31 @@ static void add_promotion(struct game_state_t *gs, const char *mstr, struct move
                return;
        }
 
+       if(gs->promoType == 3) { // handle Shogi promotions
+               piece = gs->board[mt->fromFile][mt->fromRank];
+               if(colorval(piece) == WHITE && mt->fromRank < gs->ranks - gs->ranks/3
+                                           && mt->toRank   < gs->ranks - gs->ranks/3 ) return;
+               if(colorval(piece) == BLACK && mt->fromRank >= gs->ranks/3
+                                           && mt->toRank   >= gs->ranks/3 ) return;
+                switch(piecetype(piece)) {
+                   case PAWN:
+                   case LANCE:
+                   case HONORABLEHORSE:
+                   case SILVER:
+                       if(s[1] != '+' && s[1] != '^' && s[1] != 'G' && s[1] != 'g') return;
+                       piece = GOLD; break;
+                   case BISHOP:
+                       if(s[1] != '+' && s[1] != '^' && s[1] != 'H' && s[1] != 'h') return;
+                       piece = DRAGONHORSE; break;
+                   case ROOK:
+                       if(s[1] != '+' && s[1] != '^' && s[1] != 'D' && s[1] != 'd') return;
+                       piece = DRAGONKING; break;
+                   default: return; // others do not promote, so ignore
+               }
+               mt->piecePromotionTo = piece | colorval(gs->board[mt->fromFile][mt->fromRank]);
+               return;
+       }
+
        if (piecetype(gs->board[mt->fromFile][mt->fromRank]) != PAWN) {
                return;
        }