From: H.G. Muller Date: Tue, 11 Jan 2011 15:12:02 +0000 (+0100) Subject: Fix legality testing for promotions X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=a8a8324fc365e51b7e93fb09571e90b6abb3a7d8;p=xboard.git Fix legality testing for promotions Turns out WB has never tested for the legality of the chosen promotion piece, and would allow promotion to King innorml chess even with legality testing on (when entered through the keyboard)! Now strict testing is done, outlawing Pawns and Kings (or Unicorns in Knightmate). Only in suicide / giveaway Kings are stillallowed, and in spartan a black King if you do not have two yet.(And promotion toLnce,representing Hoplite Pawn,is forbidden there.) --- diff --git a/moves.c b/moves.c index 17c1239..cb3584a 100644 --- a/moves.c +++ b/moves.c @@ -1170,10 +1170,23 @@ if(appData.debugMode)fprintf(debugFP,"SHOGI promoChar = %c\n", promoChar ? promo if (promoChar != NULLCHAR) { if(promoChar == '=') cl.kind = IllegalMove; else // [HGM] shogi: no deferred promotion outside Shogi if (cl.kind == WhitePromotion || cl.kind == BlackPromotion) { - if(CharToPiece(flags & F_WHITE_ON_MOVE ? ToUpper(promoChar) : ToLower(promoChar)) == EmptySquare) + ChessSquare piece = CharToPiece(flags & F_WHITE_ON_MOVE ? ToUpper(promoChar) : ToLower(promoChar)); + if(piece == 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 + if(gameInfo.variant == VariantSpartan && cl.kind == BlackPromotion ) { + if(promoChar != PieceToChar(BlackKing)) { + if(CheckTest(board, flags, rf, ff, rt, ft, FALSE)) cl.kind = IllegalMove; // [HGM] spartan: only promotion to King was possible + if(piece == BlackLance) cl.kind = ImpossibleMove; + } else { // promotion to King allowed only if we do not haave two yet + int r, f, kings = 0; + for(r=0; r