/*
* moves.c - Move generation and checking
- * $Id: moves.c,v 2.1 2003/10/27 19:21:00 mann Exp $
*
* 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:
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)
}
}
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;
}
}
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;
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]) == '~'
) &&
(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;
}
}
DisambiguateClosure *closure;
{
int illegal = 0; char c = closure->promoCharIn;
+
closure->count = 0;
closure->rf = closure->ff = closure->rt = closure->ft = 0;
closure->kind = ImpossibleMove;
/* [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 ||
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);