X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=moves.c;h=7ffe59df8517cb72390671185ed9cfc713c1c1c5;hb=e6e38912837a4fe2464356408d10dee950b3121c;hp=bf5ee28d2d9744c9aa45e4e1bc96471ffd2977e0;hpb=4aed6e1fe3f9c75dbb37ab41e81aed204bba602f;p=xboard.git diff --git a/moves.c b/moves.c index bf5ee28..7ffe59d 100644 --- a/moves.c +++ b/moves.c @@ -5,7 +5,7 @@ * Massachusetts. * * Enhancements Copyright 1992-2001, 2002, 2003, 2004, 2005, 2006, - * 2007, 2008, 2009, 2010, 2011, 2012, 2013 Free Software Foundation, Inc. + * 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 Free Software Foundation, Inc. * * Enhancements Copyright 2005 Alessandro Scotti * @@ -1224,6 +1224,7 @@ GenLegal (Board board, int flags, MoveCallback callback, VOIDSTAR closure, Ches if(ff <= BOARD_LEFT+2) { left = ff+1; right = BOARD_LEFT+3; } for(k=left; k<=right && ft != NoRights; k++) /* first test if blocked */ if(k != ft && board[0][k] != EmptySquare) ft = NoRights; + if(ft == 0 && ff != 1 && board[0][1] != EmptySquare) ft = NoRights; /* Rook can be blocked on b1 */ if(ff > BOARD_LEFT+2) for(k=left+1; k<=right && ft != NoRights; k++) /* then if not checked */ if(!ignoreCheck && CheckTest(board, flags, 0, ff, 0, k, FALSE)) ft = NoRights; @@ -1250,6 +1251,7 @@ GenLegal (Board board, int flags, MoveCallback callback, VOIDSTAR closure, Ches if(ff <= BOARD_LEFT+2) { left = ff+1; right = BOARD_LEFT+3; } for(k=left; k<=right && ft != NoRights; k++) /* first test if blocked */ if(k != ft && board[BOARD_HEIGHT-1][k] != EmptySquare) ft = NoRights; + if(ft == 0 && ff != 1 && board[BOARD_HEIGHT-1][1] != EmptySquare) ft = NoRights; /* Rook can be blocked on b8 */ if(ff > BOARD_LEFT+2) for(k=left+1; k<=right && ft != NoRights; k++) /* then if not checked */ if(!ignoreCheck && CheckTest(board, flags, BOARD_HEIGHT-1, ff, BOARD_HEIGHT-1, k, FALSE)) ft = NoRights; @@ -1310,6 +1312,15 @@ CheckTest (Board board, int flags, int rf, int ff, int rt, int ft, int enPassant king = flags & F_WHITE_ON_MOVE ? WhiteWazir : BlackWazir; if(gameInfo.variant == VariantKnightmate) king = flags & F_WHITE_ON_MOVE ? WhiteUnicorn : BlackUnicorn; + if(gameInfo.variant == VariantChu) { // strictly speaking this is not needed, as Chu officially has no check + int r, f, k = king, royals=0, prince = flags & F_WHITE_ON_MOVE ? WhiteMonarch : BlackMonarch; + for(r=0; r 1) return FALSE; // no check if we have two royals (ignores double captureby Lion!) + king = board[r][f]; // remember hich one we had + } + } + } if (rt >= 0) { if (enPassant) { @@ -1518,7 +1529,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 +1538,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. @@ -1984,7 +2004,8 @@ CoordsToAlgebraic (Board board, int flags, int rf, int ff, int rt, int ft, int p /* [HGM] in Shogi non-pawns can promote */ *outp++ = promoChar; // Don't bother to correct move type, return value is never used! } - else if (gameInfo.variant != VariantSuper && promoChar && + else if (gameInfo.variant == VariantChuChess && promoChar || + gameInfo.variant != VariantSuper && promoChar && (piece == WhiteLance || piece == BlackLance) ) { // Lance sometimes represents Pawn *outp++ = '='; *outp++ = ToUpper(promoChar);