From f111a0eab598dd35c865985f85a93955f4fe5b3e Mon Sep 17 00:00:00 2001 From: H.G. Muller Date: Mon, 21 Oct 2013 22:34:39 +0200 Subject: [PATCH] Fix default of Chu Chess piece promotions --- backend.c | 9 ++++++--- moves.c | 11 ++++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/backend.c b/backend.c index 14967d6..39ec535 100644 --- a/backend.c +++ b/backend.c @@ -6558,6 +6558,7 @@ HasPromotionChoice (int fromX, int fromY, int toX, int toY, char *promoChoice, i if(appData.testLegality && !premove) { moveType = LegalityTest(boards[currentMove], PosFlags(currentMove), fromY, fromX, toY, toX, IS_SHOGI(gameInfo.variant) || gameInfo.variant == VariantChuChess ? '+' : NULLCHAR); + if(moveType == IllegalMove) *promoChoice = NULLCHAR; // could be the fact we promoted was illegal if(moveType != WhitePromotion && moveType != BlackPromotion) return FALSE; } @@ -7491,8 +7492,11 @@ LeftClick (ClickType clickType, int xPix, int yPix) toY = y; } + piece = boards[currentMove][fromY][fromX]; + saveAnimate = appData.animate; if (clickType == Press) { + if(gameInfo.variant == VariantChuChess && piece != WhitePawn && piece != BlackPawn) defaultPromoChoice = piece; if(gameMode == EditPosition && boards[currentMove][fromY][fromX] == EmptySquare) { // must be Edit Position mode with empty-square selected fromX = x; fromY = y; DragPieceBegin(xPix, yPix, FALSE); dragging = 1; // consider this a new attempt to drag @@ -7508,10 +7512,8 @@ LeftClick (ClickType clickType, int xPix, int yPix) if(marker[y][x] == 5) return; // [HGM] lion: to-click on cyan square; defer action to release if(legal[y][x] == 2 || HasPromotionChoice(fromX, fromY, toX, toY, &promoChoice, FALSE)) { if(appData.sweepSelect) { - ChessSquare piece = boards[currentMove][fromY][fromX]; promoSweep = defaultPromoChoice; - if(gameInfo.variant == VariantChuChess && piece != WhitePawn && piece != BlackPawn) promoSweep = piece; else - if(PieceToChar(CHUPROMOTED piece) == '+') promoSweep = CHUPROMOTED piece; + if(gameInfo.variant != VariantChuChess && PieceToChar(CHUPROMOTED piece) == '+') promoSweep = CHUPROMOTED piece; selectFlag = 0; lastX = xPix; lastY = yPix; Sweep(0); // Pawn that is going to promote: preview promotion piece sweepSelecting = 1; @@ -7543,6 +7545,7 @@ LeftClick (ClickType clickType, int xPix, int yPix) ClearHighlights(); } #endif + if(gameInfo.variant == VariantChuChess && piece != WhitePawn && piece != BlackPawn) defaultPromoChoice = piece; if(marker[y][x] == 5) { // [HGM] lion: this was the release of a to-click or drag on a cyan square dragging *= 2; // flag button-less dragging if we are dragging MarkTargetSquares(1); diff --git a/moves.c b/moves.c index 978d895..fa41620 100644 --- a/moves.c +++ b/moves.c @@ -1518,7 +1518,8 @@ if(appData.debugMode)fprintf(debugFP,"SHOGI promoChar = %c\n", promoChar ? promo ChessSquare piece = board[rf][ff]; if(piece < BlackPawn ? piece > WhiteMan : piece > BlackMan) return ImpossibleMove; // already promoted // should test if in zone, really - if(gameInfo.variant == VariantChuChess && (piece == WhiteKnight || piece == BlackKnight)) return !HasLion(board, flags); + if(gameInfo.variant == VariantChuChess && (piece == WhiteKnight || piece == BlackKnight) && HasLion(board, flags)) + return IllegalMove; if(PieceToChar(PROMOTED piece) == '+') return flags & F_WHITE_ON_MOVE ? WhitePromotion : BlackPromotion; } else if(promoChar == '=') cl.kind = IllegalMove; else // [HGM] shogi: no deferred promotion outside Shogi @@ -1526,11 +1527,13 @@ if(appData.debugMode)fprintf(debugFP,"SHOGI promoChar = %c\n", promoChar ? promo 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 ) { + if(gameInfo.variant == VariantChuChess && promoChar == 'l' && HasLion(board, flags)) { + cl.kind = IllegalMove; // no two Lions + } else 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 + } else { // promotion to King allowed only if we do not have two yet int r, f, kings = 0; for(r=0; rkind = IllegalMove; } else if (c == '+') { // '+' outside shogi, check if pieceToCharTable enabled it ChessSquare p = closure->piece; if(p > WhiteMan && p < BlackPawn || p > BlackMan || PieceToChar(PROMOTED p) != '+') closure->kind = ImpossibleMove; // used on non-promotable piece + else if(gameInfo.variant == VariantChuChess && HasLion(board, flags)) closure->kind = IllegalMove; } else if (c != NULLCHAR) closure->kind = IllegalMove; closure->promoChar = ToLower(c); // this can be NULLCHAR! Note we keep original promoChar even if illegal. -- 1.7.0.4