Fix legality of Spartan promotion to king
authorH.G. Muller <h.g.muller@hccnet.nl>
Sat, 24 Dec 2011 16:51:22 +0000 (17:51 +0100)
committerH.G. Muller <h.g.muller@hccnet.nl>
Tue, 27 Dec 2011 11:51:21 +0000 (12:51 +0100)
In the check test promotion to King is only allowed if there are not
yet 2 kings.

moves.c

diff --git a/moves.c b/moves.c
index 093df63..199f45b 100644 (file)
--- a/moves.c
+++ b/moves.c
@@ -736,7 +736,15 @@ void GenLegalCallback(board, flags, kind, rf, ff, rt, ft, closure)
 
     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
+      if(promo) {
+           int r, f, kings=0;
+           for(r=0; r<BOARD_HEIGHT; r++) for(f=BOARD_LEFT; f<BOARD_RGHT;       f++)
+               kings += (board[r][f] == BlackKing);
+           if(kings >= 2)
+             promo = 0;
+           else
+               board[rf][ff] = BlackKing; // [HGM] spartan: promote to King before check-test
+       }
        check = CheckTest(board, flags, rf, ff, rt, ft,
                  kind == WhiteCapturesEnPassant ||
                  kind == BlackCapturesEnPassant);