Fix Spartan promotion to King
authorH.G. Muller <h.g.muller@hccnet.nl>
Sat, 8 Jan 2011 23:05:38 +0000 (00:05 +0100)
committerArun Persaud <arun@nubati.net>
Tue, 11 Jan 2011 05:22:04 +0000 (21:22 -0800)
Promotions toKing were refused when in check, because XBoard thought
they would not resolve the check. Now the promotion is actually
performed before doing the check test.

moves.c

diff --git a/moves.c b/moves.c
index 594bb12..17c1239 100644 (file)
--- a/moves.c
+++ b/moves.c
@@ -723,10 +723,15 @@ void GenLegalCallback(board, flags, kind, rf, ff, rt, ft, closure)
 {
     register GenLegalClosure *cl = (GenLegalClosure *) closure;
 
-    if (!(flags & F_IGNORE_CHECK) &&
-       CheckTest(board, flags, rf, ff, rt, ft,
+    if (!(flags & F_IGNORE_CHECK) ) {
+      int check, promo = (gameInfo.variant == VariantSpartan && kind == BlackPromotion);
+      if(promo) board[rf][ff] = BlackKing; // [HGM] spartan: promote to King before check-test
+       check = CheckTest(board, flags, rf, ff, rt, ft,
                  kind == WhiteCapturesEnPassant ||
-                 kind == BlackCapturesEnPassant)) return;
+                 kind == BlackCapturesEnPassant);
+       if(promo) board[rf][ff] = BlackLance;
+      if(check) return;
+    }
     if (flags & F_ATOMIC_CAPTURE) {
       if (board[rt][ft] != EmptySquare ||
          kind == WhiteCapturesEnPassant || kind == BlackCapturesEnPassant) {
@@ -1167,6 +1172,8 @@ if(appData.debugMode)fprintf(debugFP,"SHOGI promoChar = %c\n", promoChar ? promo
        if (cl.kind == WhitePromotion || cl.kind == BlackPromotion) {
            if(CharToPiece(flags & F_WHITE_ON_MOVE ? ToUpper(promoChar) : ToLower(promoChar)) == EmptySquare)
                 cl.kind = ImpossibleMove; // non-existing piece
+           if(gameInfo.variant == VariantSpartan && cl.kind == BlackPromotion && promoChar != PieceToChar(BlackKing) &&
+              CheckTest(board, flags, rf, ff, rt, ft, FALSE)) cl.kind = IllegalMove; // [HGM] spartan: only promotion to King was possible
        } else {
            cl.kind = IllegalMove;
        }