X-Git-Url: http://winboard.nl/cgi-bin?p=xboard.git;a=blobdiff_plain;f=moves.c;h=2a017c3c54892aa62842455f703bc8fa298ecc7c;hp=04c0dd750b32f49ea2c308568c2b33e9f4ee4a3f;hb=ca99bd4de57d0b079024cbdf5435de1ae61d5fd9;hpb=7b4dacf6fe9f8c10b6eb4d6070869a3d933dbeb5 diff --git a/moves.c b/moves.c index 04c0dd7..2a017c3 100644 --- a/moves.c +++ b/moves.c @@ -2,9 +2,12 @@ * moves.c - Move generation and checking * * Copyright 1991 by Digital Equipment Corporation, Maynard, - * Massachusetts. Enhancements Copyright - * 1992-2001,2002,2003,2004,2005,2006,2007,2008,2009 Free Software - * Foundation, Inc. + * Massachusetts. + * + * Enhancements Copyright 1992-2001, 2002, 2003, 2004, 2005, 2006, + * 2007, 2008, 2009 Free Software Foundation, Inc. + * + * Enhancements Copyright 2005 Alessandro Scotti * * The following terms apply to Digital Equipment Corporation's copyright * interest in XBoard: @@ -66,7 +69,7 @@ int BlackPiece P((ChessSquare)); int SameColor P((ChessSquare, ChessSquare)); int PosFlags(int index); -extern char initialRights[BOARD_SIZE]; /* [HGM] all rights enabled, set in InitPosition */ +extern signed char initialRights[BOARD_SIZE]; /* [HGM] all rights enabled, set in InitPosition */ int WhitePiece(piece) @@ -677,6 +680,14 @@ void GenPseudoLegal(board, flags, epfile, callback, closure) } } break; + case WhiteFalcon: // [HGM] wild: for wildcards, self-capture symbolizes move to anywhere + case BlackFalcon: + case WhiteCobra: + case BlackCobra: + case WhiteLance: + case BlackLance: + callback(board, flags, NormalMove, rf, ff, rf, ff, closure); + break; } } @@ -1050,7 +1061,7 @@ ChessMove LegalityTest(board, flags, epfile, castlingRights, rf, ff, rt, ft, pro if(piece == WhiteFalcon || piece == BlackFalcon || piece == WhiteCobra || piece == BlackCobra || piece == WhiteLance || piece == BlackLance) - return NormalMove; + return CheckTest(board, flags, rf, ff, rt, ft, FALSE) ? IllegalMove : NormalMove; cl.rf = rf; cl.ff = ff; @@ -1192,6 +1203,13 @@ void DisambiguateCallback(board, flags, kind, rf, ff, rt, ft, closure) VOIDSTAR closure; { register DisambiguateClosure *cl = (DisambiguateClosure *) closure; + int wildCard = FALSE; ChessSquare piece = board[rf][ff]; + + // [HGM] wild: for wild-card pieces rt and rf are dummies + if(piece == WhiteFalcon || piece == BlackFalcon || + piece == WhiteCobra || piece == BlackCobra || + piece == WhiteLance || piece == BlackLance) + wildCard = TRUE; if ((cl->pieceIn == EmptySquare || cl->pieceIn == board[rf][ff] || PieceToChar(board[rf][ff]) == '~' @@ -1199,15 +1217,15 @@ void DisambiguateCallback(board, flags, kind, rf, ff, rt, ft, closure) ) && (cl->rfIn == -1 || cl->rfIn == rf) && (cl->ffIn == -1 || cl->ffIn == ff) && - (cl->rtIn == -1 || cl->rtIn == rt) && - (cl->ftIn == -1 || cl->ftIn == ft)) { + (cl->rtIn == -1 || cl->rtIn == rt || wildCard) && + (cl->ftIn == -1 || cl->ftIn == ft || wildCard)) { cl->count++; cl->piece = board[rf][ff]; cl->rf = rf; cl->ff = ff; - cl->rt = rt; - cl->ft = ft; + cl->rt = wildCard ? cl->rtIn : rt; + cl->ft = wildCard ? cl->ftIn : ft; cl->kind = kind; } } @@ -1218,6 +1236,7 @@ void Disambiguate(board, flags, epfile, closure) DisambiguateClosure *closure; { int illegal = 0; char c = closure->promoCharIn; + closure->count = 0; closure->rf = closure->ff = closure->rt = closure->ft = 0; closure->kind = ImpossibleMove; @@ -1249,24 +1268,10 @@ void Disambiguate(board, flags, epfile, closure) /* [HGM] Shogi promotions. '=' means defer */ if(closure->rfIn != DROP_RANK && closure->kind == NormalMove) { ChessSquare piece = closure->piece; -#if 0 - if (appData.debugMode) { - fprintf(debugFP, "Disambiguate A: %d(%d,%d)-(%d,%d) = %d (%c)\n", - closure->pieceIn,closure->ffIn,closure->rfIn,closure->ftIn,closure->rtIn, - closure->promoCharIn,closure->promoCharIn); - } -#endif if(c != NULLCHAR && c != 'x' && c != '+' && c != '=' && ToUpper(PieceToChar(PROMOTED piece)) != ToUpper(c) ) closure->kind = IllegalMove; else if(flags & F_WHITE_ON_MOVE) { -#if 0 - if (appData.debugMode) { - fprintf(debugFP, "Disambiguate B: %d(%d,%d)-(%d,%d) = %d (%c)\n", - closure->pieceIn,closure->ffIn,closure->rfIn,closure->ftIn,closure->rtIn, - closure->promoCharIn,closure->promoCharIn); - } -#endif if( (int) piece < (int) WhiteWazir && (closure->rf > BOARD_HEIGHT-4 || closure->rt > BOARD_HEIGHT-4) ) { if( (piece == WhitePawn || piece == WhiteQueen) && closure->rt > BOARD_HEIGHT-2 || @@ -1300,13 +1305,6 @@ void Disambiguate(board, flags, epfile, closure) closure->kind = IllegalMove; } } -#if 0 - if (appData.debugMode) { - fprintf(debugFP, "Disambiguate C: %d(%d,%d)-(%d,%d) = %d (%c)\n", - closure->pieceIn,closure->ffIn,closure->rfIn,closure->ftIn,closure->rtIn, - closure->promoCharIn,closure->promoCharIn); - } -#endif /* [HGM] returns 'q' for optional promotion, 'n' for mandatory */ if(closure->promoCharIn != '=') closure->promoChar = ToLower(closure->promoCharIn);